Repository navigation
Give each annotation its object numbers once, instead of predicting them in PageWriter - #360
Merged
jakejackson1 merged 1 commit intoSep 23, 2026
Conversation
…hem in PageWriter MetadataWriter::numberAnnotations() numbers every link, annotation (with its popup or embedded file and PDF/A appearance), form widget and radio group in the order writeAnnotations() writes them. writeAnnotations() then writes each object under its number and refers to the others by number, not by offset from the one it is writing. PageWriter writes /Annots from the numbers it is handed. The output is byte-identical. Fixes #352 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 23, 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.
Stacks on #330.
Mechanism
MetadataWriter::numberAnnotations($id)replacessettleAnnotations()+annotationObjectCount()and the two counting loops inPageWriter::writePages(). It settles each annotation's file first, then walks the pages once, in the orderwriteAnnotations()writes:$linkIds[$page][$key], soPageLinksentries keep their shape)$pl['ids'] = ['annot' => …, 'file' => … | 'popup' => …, 'appearance' => …](appearance only under PDF/A), pluspageobjForm::addFormIds(), which now appends to an array rather than a stringobj_idafter the last pageIt returns each page's
/Annotslist: links, annotations, popups that have no file, and widgets.PageWriterjust writes that list.writeAnnotations()starts each object withbeginObject($id), which callsBaseWriter::object($id)and sets$mpdf->nto that number so the form code that follows can keep numbering in sequence./EF,/Popup,/Parentand/APnow use$ids[…]instead ofn + 1,n - 1andn + annotationObjectCount() - 1. The layout rule is now in one place. Other changes:Form::countPageForms()is gone, andPageWriterno longer takesForm.Output is byte-identical
composer test -- --group=snapshot: 85/85 pass, no "bytes differ" orsnapshot:updatenotes. None in the full run either.cmp. All were identical. They covered two pages of links, popups (default size and placed), a file annotation, a coloured note, and active forms with text/JS, checkbox, select and two radio groups, under no files / files allowed / PDF/A-1b / PDF/A-2b / PDF/A-3b. The encrypted variants are random on every run, so I left them out of the comparison.Tests
The new
tests/Mpdf/AnnotationObjectNumbersTest.phpbuilds two pages with links, notes with and without popups, a file note, and (without PDF/A) active widgets with a radio group on each page. It runs under four setups: file not allowed + forms, file allowed + forms, PDF/A-2b (file dropped) and PDF/A-3b (file embedded). It checks that:/Sizeis written/Annotslists exactly the expected subtypes in order, each a/Type /Annot/Pnames the page/Popupnames a listed Popup whose/Parentpoints back/EFnames an EmbeddedFile, and/APnames a Form XObject/Parentlists it in/KidsI mutated the code four ways (a wrong
/Parent,/EF,/APor radio group number). The test caught every one.PDFA2Test::testAnnotsListOnlyAnnotationspasses unchanged.Gates
composer test: 3226 tests OK. The 5 skips are the usual unpacked-Unicode/HarfBuzz/ICU generator checks.composer cs: cleanphp -lon the changed files: OKphpunit --group=conformance --fail-on-skipped(veraPDF): 10/10 OKFixes #352
🤖 Generated with Claude Code