You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reader fails on object streams (/ObjStm): "object N not found in xref" #35
The PDF reader does not support compressed object streams (/ObjStm, i.e. type-2 cross-reference entries). Any PDF written with a cross-reference stream (/Type /XRef, PDF 1.5+) that stores objects inside object streams fails to read/merge with:
pdf: object <N> not found in xref
Because most modern PDF producers emit object streams by default, this affects a large share of real-world PDFs — not an edge case.
Steps to Reproduce
Take any valid PDF and ensure it uses object streams (most modern tools do this already; to force it):
data, _:=os.ReadFile("objstm.pdf")
_, err:=gpdf.Merge([]gpdf.Source{{Data: data}})
// err: "pdf: source 0: pdf: object <N> not found in xref"
Expected Behavior
The reader should support compressed object streams per the PDF spec (ISO 32000, cross-reference streams §7.5.8 and object streams §7.5.7):
In parseXRefEntries, handle type-2 entries: field[1] = object number of the containing /ObjStm, field[2] = index of the object within that stream.
Add an object-stream reader: given an /ObjStm object, decode its stream, parse the N header pairs (object number / offset) up to /First, and resolve the requested object from the decompressed body. Caching the parsed /ObjStm avoids re-decoding for sibling objects.
With those two pieces, GetObject resolves type-2 objects and object-stream-based PDFs read and merge correctly.
Actual Behavior
Reading/merging the PDF fails with:
pdf: object <N> not found in xref
The object exists in the file inside a compressed object stream (type-2 xref entry), but the reader ignores type-2 entries so GetObject never finds it. The file is valid and opens fine in macOS Preview.
I'd like to work on this and open a PR with a fix, but it looks like the repo restricts pull request creation to collaborators. Could I be added as a collaborator so I can submit one? Happy to follow whatever branch and review conventions you prefer. Thanks!
The reader now handles type-2 (compressed) xref entries and resolves objects from /ObjStm, with the decoded object stream cached for sibling lookups. Stream predictors are supported as well, and a related fix ensures incremental updates write 20-byte xref entries. Object-stream PDFs are now covered in _validation.
@ElephantsFoot thanks for the detailed report — the pointers to §7.5.7/§7.5.8 and the qpdf --object-streams=generate repro made this straightforward to fix. Sorry for not getting back to you about collaborator access before shipping it. Contributions are very welcome; the flow is to fork the repo and open a PR from your fork (see CONTRIBUTING.md), no collaborator access needed.
Activity
ElephantsFoot commentedon Jul 23, 2026
I'd like to work on this and open a PR with a fix, but it looks like the repo restricts pull request creation to collaborators. Could I be added as a collaborator so I can submit one? Happy to follow whatever branch and review conventions you prefer. Thanks!
Merge pull request #38 from gpdf-dev/fix/objstm-support
taiki-nd commentedon Sep 3, 2026
Fixed and released in v1.0.12.
The reader now handles type-2 (compressed) xref entries and resolves objects from
/ObjStm, with the decoded object stream cached for sibling lookups. Stream predictors are supported as well, and a related fix ensures incremental updates write 20-byte xref entries. Object-stream PDFs are now covered in_validation.@ElephantsFoot thanks for the detailed report — the pointers to §7.5.7/§7.5.8 and the
qpdf --object-streams=generaterepro made this straightforward to fix. Sorry for not getting back to you about collaborator access before shipping it. Contributions are very welcome; the flow is to fork the repo and open a PR from your fork (see CONTRIBUTING.md), no collaborator access needed.fix(pdf): support compressed object streams and stream predictors (gp…