Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the PDFBox builtin image direct embedding #628

Merged

Conversation

rototor
Copy link
Contributor

@rototor rototor commented Dec 30, 2020

And don't try to do this ourself. Since some releases PDFBox is able
to not only directly (i.e. without re-encoding) embed images, but
also to directly embed PNG images. TIFF images are supported if
they are in CCITT (i.e. Fax) format.

Note: The PNG direct embedding only works for some PNG encodings,
for details see https://issues.apache.org/jira/browse/PDFBOX-4341

This allows to manually optimise Images using e.g. ImageOptim and benefit
from this optimized images.

If it is not possible to directly embed an image PDFBox falls back to
ImageIO.read() and the LosslessFactory.createFromImage().

In the worst case, this patch may make PDFs bigger, as the
provided image files may be in a worse compression quality
(file size wise) then the LosslessFactory would do when compressing.

But in the best case the PDF writing gets faster, as not every image
needs to be decompressed and compressed again. And the PDFs could get
smaller if the images have been preoptimized.

And don't try to do this ourself. Since some releases PDFBox is able
to not only directly (i.e. without re-encoding) embed images, but
also to directly embed PNG images. TIFF images are supported if
they are in CCITT (i.e. Fax) format.

Note: The PNG direct embedding only works for some PNG encodings,
for details see https://issues.apache.org/jira/browse/PDFBOX-4341

This allows to manually optimise Images using e.g. ImageOptim and benefit
from this optimized images.

If it is not possible to directly embed an image PDFBox falls back to
ImageIO.read() and the LosslessFactory.createFromImage().

In the worst case, this patch may make PDFs bigger, as the
provided image files may be in a worse compression quality
(file size wise) then the LosslessFactory would do when compressing.

But in the best case the PDF writing gets faster, as not every image
needs to be decompressed and compressed again. And the PDFs could get
smaller if the images have been preoptimized.
@danfickle
Copy link
Owner

Fully agree. Thanks again.

@danfickle danfickle merged commit 1290eba into danfickle:open-dev-v1 Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants