Repository navigation
Add an objectStreams option to write PDF 1.5 object streams - #1813
Merged
Merged
Conversation
…ence stream Packs the objects that are not streams into compressed PDF 1.5 object streams, and writes a cross-reference stream instead of the xref table, making documents with many such objects, e.g. tagged ones, much smaller. Off by default; requires a pdfVersion of 1.5 or higher, and cannot be used with encryption or PDF/A-1.
tomsotte
marked this pull request as ready for review
October 8, 2026 09:17
Member
|
LGTM Please fix the conflict |
asmyshlyaev177
pushed a commit
to asmyshlyaev177/pdfkit
that referenced
this pull request
Oct 10, 2026
…1813) * Add an objectStreams option to write object streams and a cross-reference stream Packs the objects that are not streams into compressed PDF 1.5 object streams, and writes a cross-reference stream instead of the xref table, making documents with many such objects, e.g. tagged ones, much smaller. Off by default; requires a pdfVersion of 1.5 or higher, and cannot be used with encryption or PDF/A-1. * Name the cross-reference stream entry constants and reference foliojs#1810
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What kind of change does this PR introduce?
A feature, closes #1810. It adds an opt-in
objectStreamsoption that writes PDF 1.5 object streams and a cross-reference stream.Objects without a stream are packed into compressed
/ObjStmobjects, up to 200 per stream. Examples are structure elements, annotations, font dictionaries and the catalog. A single/XRefstream replaces the xref table and the trailer. How much smaller a file gets depends on how many of these small objects it has, so tagged documents gain the most:qpdf --object-streams=generatemakes the same file 379 KB.Changes:
lib/object_streams.js:reference.jshands it the objects that have no stream.document.jshas it write the xref stream at the end._refEndnow resets_endedbefore calling_finalize. Writing the last object stream ends one more reference, and without this reset the xref would be written twice.pdfVersionbelow 1.5;Testing:
compress: false, tagged PDF/A-2, and every case that throws.qpdf --check, except the ones that already failed it, which have no pages or are encrypted.Checklist:
I wrote this with the help of AI, then reviewed the code and checked the output myself.