Fix PDF spec compliance, git line-ending corruption, and add xref validation test#691
Merged
Fix PDF spec compliance, git line-ending corruption, and add xref validation test#691
Conversation
Co-authored-by: Shane32 <6377684+Shane32@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix PDF creation to ensure Kids references are indirect
Fix PDF creation: /Kids must contain indirect Page references
Feb 21, 2026
Shane32
reviewed
Feb 21, 2026
Shane32
approved these changes
Feb 21, 2026
Co-authored-by: Shane32 <6377684+Shane32@users.noreply.github.com>
Co-authored-by: Shane32 <6377684+Shane32@users.noreply.github.com>
Copilot
AI
changed the title
Fix PDF creation: /Kids must contain indirect Page references
Fix PDF spec compliance, git line-ending corruption, and add xref validation test
Feb 21, 2026
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.
The PDF renderer produced invalid files in two ways: the
/Kidsarray embedded an inline page dictionary (violating the PDF spec, which requires indirect references), andwriter.WriteLine()emitted platform-specific line endings causing xref byte offsets to be wrong when git normalized line endings on checkout.PDF structure fix
/Kidsmust contain only indirect object references. Restructured from 3 objects to 4:/Kids [ 3 0 R ]— indirect reference instead of inline dict/Contents 4 0 REncoding.ASCII.GetByteCount(content)Cross-platform line endings
writer.WriteLine()emitsEnvironment.NewLine, which is\non Linux and\r\non Windows. Since all other PDF output uses explicit\r\n, replaced withwriter.Write("\r\n")for consistent output everywhere.Git binary attribute
.gitattributeshad* text=autowith.pdfonly markeddiff=astextplain— notbinary. Git was stripping\rfrom PDF files on Linux checkout, making xref offsets wrong by 1 byte per newline. Changed to:Approved snapshots
All 6 approved PDF snapshots regenerated. They now have consistent CRLF endings and correct xref offsets on all platforms.
Xref validation test
Added
pdf_xref_table_is_validtoPdfByteQRCodeRendererTests— generates a PDF, locatesstartxreffrom the end, parses the full xref table, and asserts that every in-use entry's byte offset points to the correctN 0 objline.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.