ImageMagickObject creates broken PDF when using byte array
Posted: 2007-01-12T05:55:45-07:00
Hi, ImageMagick gurus
I'm trying to create PDF's using ImageMagickObject in asp code on an IIS 6.0 web server, streaming the PDF directly to the browser.
It works OK for single page PDF's, but multi-page PDF's are damaged and cannot open.
Testing has showed, that the problem only occurs when ImageMagickObject is converting into a byte array (to use for Response.BinaryWrite in the asp code.)
But when ImageMagickObject writes a file directly, the PDF's are created correctly and perfectly valid.
Problem has been reproduced on two servers:
Server A: Win 2003 Standard Edition SP 1, IIS 6.0, ImageMagick-6.3.1-Q16
Server B: Win 2003 Web Edition SP 1, IIS 6.0, ImageMagick-6.3.1-Q8
I have made a testcase using two small jpegs for input and creating one-page and two-page PDF's both as file and byte array.
Both PDF's created as byte array have errors - but the one-page can be opened and viewed, the two-page is too damaged and cannot be opened.
Testcase can be downloaded from http://media.thg.dk/DAT/imagemagickbug/ ... entBug.zip
Zip-file contains:
bugtest1.jpg
bugtest2.jpg
bugtest1page.asp
bugtest2page.asp
bugtest_1page_file.pdf
bugtest_1page_response.pdf
bugtest_2page_file.pdf
bugtest_2page_response.pdf
The 2 jpegs are the inputs I use for converting to pdf.
The 2 asp files contain the code for the 4 tests I create.
The 4 pdf files are the results of the 4 tests.
In bugtest1page.asp I do two tests creating a one-page pdf - one test directly to file, one test to byte array for streaming the pdf directly to the browser.
- Test 1 - convert one jpeg to a one-page pdf to file:
msg= MagickImage.convert( "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest_1page_file.pdf" )
This works fine - creates a perfectly valid pdf file 16435 bytes large (bugtest_1page_file.pdf)
- Test 2 - convert one jpeg to a one-page pdf to byte array:
image2(0)="PDF:"
msg= MagickImage.convert( "C:\WWW\root\kbh\bugtest1.jpg", image2 )
<code to stream to asp response>
This works almost fine - creates a pdf file 16411 bytes large (bugtest_1page_response.pdf)
The pdf file can be opened and looks OK, but when I close Adobe Acrobat Professional, I'm prompted "Do you want to save changes to bugtest_1page_response.pdf before closing?"
In bugtest2page.asp I do two similar tests - but create a two-page pdf instead.
- Test 3 - convert two jpegs to a two-page pdf to file:
msg= MagickImage.convert( "-adjoin", "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest2.jpg", "C:\WWW\root\kbh\bugtest_2page_file.pdf" )
This works fine - creates a perfectly valid two-page pdf file 34716 bytes large (bugtest_2page_file.pdf)
- Test 4 - convert two jpegs to a two-page pdf to byte array:
image2(0)="PDF:"
msg= MagickImage.convert( "-adjoin", "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest2.jpg", image2 )
<code to stream to asp response>
This does not work - creates a malformed pdf file 15975 bytes large (bugtest_2page_response.pdf)
When I try to open this pdf file, I get a box "There was an error opening this document. The file is damaged and could not be repaired."
It seems to me, that creating a pdf to byte array does not write the entire result to the bytearray? Or something like that?
When creating the pdf to file, everything works perfectly - so I tentatively conclude, that the error must be in the handling of the byte array in the component?
(Or that I do something wrong, which is quite possible )
I hope either I can get information on what I'm doing wrong - or confirmation it is a bug and that it is "fixable" )
I'm developing an application (for our internal use) for opening multipage tiff files (scanned documents), add stamps to each page ("Approved","Confidential",etc), and present the result as a PDF to the user's browser.
ImageMagick is just brilliant for that purpose - except for this problem with multipage PDF creation to byte array )
Regards
Kim Berg Hansen
Senior System Developer
T. Hansen Gruppen A/S
PS. Thanks to everyone contributing to ImageMagick - it's like having a programmable PhotoShop )
I'm trying to create PDF's using ImageMagickObject in asp code on an IIS 6.0 web server, streaming the PDF directly to the browser.
It works OK for single page PDF's, but multi-page PDF's are damaged and cannot open.
Testing has showed, that the problem only occurs when ImageMagickObject is converting into a byte array (to use for Response.BinaryWrite in the asp code.)
But when ImageMagickObject writes a file directly, the PDF's are created correctly and perfectly valid.
Problem has been reproduced on two servers:
Server A: Win 2003 Standard Edition SP 1, IIS 6.0, ImageMagick-6.3.1-Q16
Server B: Win 2003 Web Edition SP 1, IIS 6.0, ImageMagick-6.3.1-Q8
I have made a testcase using two small jpegs for input and creating one-page and two-page PDF's both as file and byte array.
Both PDF's created as byte array have errors - but the one-page can be opened and viewed, the two-page is too damaged and cannot be opened.
Testcase can be downloaded from http://media.thg.dk/DAT/imagemagickbug/ ... entBug.zip
Zip-file contains:
bugtest1.jpg
bugtest2.jpg
bugtest1page.asp
bugtest2page.asp
bugtest_1page_file.pdf
bugtest_1page_response.pdf
bugtest_2page_file.pdf
bugtest_2page_response.pdf
The 2 jpegs are the inputs I use for converting to pdf.
The 2 asp files contain the code for the 4 tests I create.
The 4 pdf files are the results of the 4 tests.
In bugtest1page.asp I do two tests creating a one-page pdf - one test directly to file, one test to byte array for streaming the pdf directly to the browser.
- Test 1 - convert one jpeg to a one-page pdf to file:
msg= MagickImage.convert( "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest_1page_file.pdf" )
This works fine - creates a perfectly valid pdf file 16435 bytes large (bugtest_1page_file.pdf)
- Test 2 - convert one jpeg to a one-page pdf to byte array:
image2(0)="PDF:"
msg= MagickImage.convert( "C:\WWW\root\kbh\bugtest1.jpg", image2 )
<code to stream to asp response>
This works almost fine - creates a pdf file 16411 bytes large (bugtest_1page_response.pdf)
The pdf file can be opened and looks OK, but when I close Adobe Acrobat Professional, I'm prompted "Do you want to save changes to bugtest_1page_response.pdf before closing?"
In bugtest2page.asp I do two similar tests - but create a two-page pdf instead.
- Test 3 - convert two jpegs to a two-page pdf to file:
msg= MagickImage.convert( "-adjoin", "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest2.jpg", "C:\WWW\root\kbh\bugtest_2page_file.pdf" )
This works fine - creates a perfectly valid two-page pdf file 34716 bytes large (bugtest_2page_file.pdf)
- Test 4 - convert two jpegs to a two-page pdf to byte array:
image2(0)="PDF:"
msg= MagickImage.convert( "-adjoin", "C:\WWW\root\kbh\bugtest1.jpg", "C:\WWW\root\kbh\bugtest2.jpg", image2 )
<code to stream to asp response>
This does not work - creates a malformed pdf file 15975 bytes large (bugtest_2page_response.pdf)
When I try to open this pdf file, I get a box "There was an error opening this document. The file is damaged and could not be repaired."
It seems to me, that creating a pdf to byte array does not write the entire result to the bytearray? Or something like that?
When creating the pdf to file, everything works perfectly - so I tentatively conclude, that the error must be in the handling of the byte array in the component?
(Or that I do something wrong, which is quite possible )
I hope either I can get information on what I'm doing wrong - or confirmation it is a bug and that it is "fixable" )
I'm developing an application (for our internal use) for opening multipage tiff files (scanned documents), add stamps to each page ("Approved","Confidential",etc), and present the result as a PDF to the user's browser.
ImageMagick is just brilliant for that purpose - except for this problem with multipage PDF creation to byte array )
Regards
Kim Berg Hansen
Senior System Developer
T. Hansen Gruppen A/S
PS. Thanks to everyone contributing to ImageMagick - it's like having a programmable PhotoShop )