"pdf width or height is below 3.00 - too small for some viewers!" from JPEG2000 file #186
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?
I have some scanned images that I've converted from TIFF to JPEG2000 using the Kakadu
kdu_compress
command. The files behave fine in every viewer, andexiftool
shows:However, trying to convert that file (and any others I've tried), gives:
If it'll help, the above test file is here .
Yes, that seems correct. Where do you see the bug? What would you expect to happen instead?
Well ... image to PDF :) img2pdf doesn't like those files: however, if I take the .jp2 file into another application (GraphicConverter on MacOS), and re-save it, img2pdf processes that correctly without any issues. So there's something about the source image that it doesn't like.
Comparing the before (non-working) and after (working) files, the only difference is:
Before:
Capture Y Resolution Unit : 10 m
Capture X Resolution Unit : 10 m
After:
Capture Y Resolution Unit : 0.1 mm
Capture X Resolution Unit : 0.1 mm
10m does seem very strange, and I've no idea why
kdu_compress
is settling those values.However, now that I've spotted that, I've come up with a workaround: remove the problem metadata using exiv2:
and so
works fine.
Apologies for the "false positive": img2pdf was never doing anything wrong, just picking up some crazy values that were otherwise non-obvious to me.
Do you see anything img2pdf could do better to inform you of what is going on?
Given that stripping out the metadata seems to fix the issue, I'm assuming that img2pdf is reading some of the data, doing a calculation and deciding it's not safe/sensible to proceed. Again, the images look fine on all the viewers I've tried, so it's must just be a metadata issue.
I'm not sure it would be practical (or even possible) for an option within img2pdf to ignore, or override, the metadata values? This may just been an extreme edge case with my images, so whether it brings any real value to anyone else is questionable.
Thanks for a great tool!
So the error you see doesn't actually come from img2pdf but from the library it uses to create the pdf (pikepdf). That library refuses to create a PDF page which is so small that it violates the PDF spec. In this case (and you can try this yourself by forcing img2pdf to use its internal engine which doesn't care about page sizes using
--engine=internal
) the pdf page would have a width and a height of zero.How are these sizes computed? Indeed the dpi embedded into the image is used to convert from pixels to an actual physical length. So maybe what img2pdf could do is to tell the user that the impossible page size is due to the combination of dpi and image size and that those can be overridden using the
-s
or--imgsize
options.For example in your case, you can create a valid pdf using this:
Which will compute the page size using the custom dpi value of 600. You can also specify a custom size (DIN A4 in this case) like this:
Maybe part of the above should be in the error message?