11x9 image cannot be opened in Acrobat Reader (file is corrupt) #19
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
By josch on 2015-03-15T09:41:53.361Z
Created by: ysangkok
The following PNM file (
img.pnm
):converted to JP2 with
convert img.pnm img.jp2
or with jasper:jasper -f img.pnm -F img.jp2
, converted to PDF with~/img2pdf/img2pdf.py img.jp2 -o img.pdf
, opened in Adobe Acrobat Reader, gives me the following error message:"An error exists on this page".
Imported comments:
By josch on 2012-10-17 04:00:05 UTC
Did you do more tests?
By ysangkok on 2012-10-17 10:02:34 UTC
By josch on 2012-10-17 13:38:52 UTC
By ysangkok on 2012-10-17 13:44:12 UTC
I used
convert logo: -monochrome bigimg.jp2
now. The error in acroread is now "Insufficient data for an image". Evince shows something very similar to this image produced bypdftoppm
from Ubuntu Xpdf: http://i.imgur.com/MAzaa.png Note that it's square.pdftoppm
from the Xpdf 3.03 binary from the official site produces this: http://i.imgur.com/iXGmi.pngI am sure Poppler understands JPEG-2000 because big coloured images are usually OK. For example, if I remove
-monochrome
in the command above, everything works.Thank you for your patience and quick responses.
By josch on 2012-10-18 05:48:44 UTC
oh wait so monochrome doesnt work but rgb does - then we might have a solution here!
I just found a code comment for the jpeg2000 portion of my code: "TODO: read real colorspace"
Right now, it defaults to assign RGB to jepeg2000. This is because python imaging can't read jpeg2000 metadata.
Can you try to open your pdf in a text editor and replace:
/ColorSpace /DeviceRGB
by
/ColorSpace /DeviceGray
Or remove the line entirely.
And try the same with replacing:
/BitsPerComponent 8
by
/BitsPerComponent 1
Or remove the line entirely again.
And check if it works?
By ysangkok on 2012-10-18 11:58:23 UTC
It is not just "monochrome works, rgb doesn't". Using
DeviceGray
fixes it for this image. But the PPM example I linked above is still broken. But that image shows in every other viewer than Acroread, so I think Acroread might be broken. It doesn't even work when the converted with ImageMagick:convert colored.ppm colored.pdf
. So that's probably not a Img2pdf problem.If I use
convert logo: -monochrome -depth 8 -type TrueColor bigimg.jp2
, it works too. RGBA images are broken too, but that makes sense now.By josch on 2012-10-18 15:00:43 UTC
So lets first look at the big image.
You say that using /DeviceGray fixes the issue for that one. Unfortunately I didnt figure out how to easily retrieve the colorspace from a jpeg2000 image yet. This will be more effort...
As a temporary solution I added the -C or --colorspace option that you can use to force grayscale colorspace. So you now can do img2pdf -C L in.jp2 -o out.pdf. L is grayscale in PIL terms. The --help lists more possible modes.
But you say that even with /DeviceGray the small image is still broken. Maybe acroread simply doesnt like tiny jpeg2000 images? Are also tiny RGB images broken in acroread?
By ysangkok on 2012-10-18 17:12:57 UTC
I know Acrobat Reader can handle tiny JPEG-2000 images, cause it handles the original monochrome triangle once I patch it to say "DeviceGray" (this trick of course also fixes the monochrome ImageMagick logo). But it doesn't handle the tiny colored image. My last post referenced the colored PNM image linked (not the one in #0, that one's monochrome). That's why it's called
colored.pnm
.So yes, tiny RGB image parsing is probably broken in Acrobat Reader, unless Evince parses an invalid picture and shows it as intended. Also, the same image converted directly to PDF with ImageMagick also doesn't show in Acroread.
Acrobat Reader handles big RGB PDF's fine (like the colored ImageMagick logo).
Thanks for the patch.
Here's base64 of
colored.jp2
in case you don't have ImageMagick or NetPBM:By josch on 2013-10-23 06:27:45 UTC
With my latest changes your original 11x9 image now works fine in acroread. Unfortunately the pnm example from wikipedia still doesnt work so I investigated a bit more and it indeed seems to be the image size that matters here:
From the pdfs that above code produces, acroread was only able to show those where width and height both were greater or equal to four pixels.
But since this restriction is rather odd because pdf should not be limited to include images of more than 3 pixels in either dimension, I additionally checked whether it was maybe instead the page size that mattered by just changing the dpi of the one pixel image:
It turns out that with a low enough dpi value (everything lower than 25) the 1x1 image displays just fine. Further fiddling with manually editing the /MediaBox size yielded that the /MediaBox must be of at least 3.00 in width and height for acroread to display the pdf correctly.
Therefore, the solution to this problem is, to just increase the dpi values for images which are very small so that the resulting pdf page becomes big enough nevertheless.
Does this fix your problem?
By josch on 2017-01-21T07:53:48.711Z
Closing because of no reply from original submitter.
By josch on 2017-01-21T07:53:48.921Z
Status changed to closed