Use the PDFBox builtin image direct embedding #628
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.