feat(pdf): reproducible output via a deterministic() backend option#363
Merged
Conversation
26d87a1 to
c645864
Compare
PdfFixedLayoutBackend.builder().deterministic(true) (or .deterministic(Instant)) pins the document CreationDate / ModDate and derives the PDF /ID from the document metadata instead of PDFBox's time-seeded default, so the same document renders to byte-identical PDF output across runs — for reproducible builds and byte-level output tests. Off by default; existing output keeps the live timestamp and /ID. Applied on both the render and section-render paths.
c645864 to
b791838
Compare
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.
Why
The same document rendered twice produced different PDF bytes: PDFBox seeds the document
/IDfrom the current time on every save, and that
/IDwas the only source of non-determinism(GraphCompose never set a CreationDate). That blocks reproducible builds and byte-level output
assertions.
What
PdfFixedLayoutBackend.builder().deterministic(true)— enables reproducible output: pins thedocument CreationDate / ModDate to a fixed default timestamp and sets the PDF
/IDto a stablevalue derived from the document's info dictionary (MD5), instead of PDFBox's time-seeded
/ID..deterministic(Instant)— the same, with an explicit timestamp.deterministicTimestamp == null): output is unchanged — live timestamp andPDFBox
/ID.buildDocument(render / toBytes) andbuildSectionsDocument(the@Betasection-render path).
Tests
PdfDeterministicOutputTest(3): the same document rendered twice withdeterministic(true)is byte-identical;
deterministic(Instant)pins the CreationDate to that instant; the defaultbackend leaves the CreationDate unset (proving it's opt-in).
./mvnw -f aggregator/pom.xml verify -pl :graph-compose-qa -am— full compile + javadoc gate +the qa visual/parity byte-identity suite (643): green. The default path is a no-op, so existing
rendered output is unchanged.
Architectural note: determinism is a PDF-serialization concern (
/ID, dates), so the knob lives onthe PDF backend builder rather than the canonical
DocumentSession— it keeps a format-specificdetail out of the backend-neutral document model.