Skip to content

Write a PDF/A-3 annotation's file as an associated file, so it passes veraPDF - #358

Merged
jakejackson1 merged 2 commits into
feature/pdfa-2-conformancefrom
fix/347-pdfa-3-annotation-attachments
Sep 23, 2026
Merged

jakejackson1 merged 2 commits into
feature/pdfa-2-conformancefrom
fix/347-pdfa-3-annotation-attachments

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Stacks on #330.

What changed

Under PDF/A-3, veraPDF failed an <annotation file="…"> attachment on rules 6.8-1, 6.8-3 and 6.8-4. The embedded file had no MIME type, the file spec had no /AFRelationship, and nothing associated the file spec with the document. MetadataWriter now writes these attachments through the same code as SetAssociatedFiles():

  • Pulled the per-file body of writeAssociatedFiles() out into a private writeAssociatedFile(array $file), which returns the file spec's object number. writeAssociatedFiles() output is byte-identical.
  • Under PDF/A-3, a file annotation writes /FS n 0 R /AF [n 0 R], then passes the file to writeAssociatedFile() with AFRelationship Unspecified and MIME application/octet-stream. The file spec is now its own object, so each file annotation writes one more object. annotationObjectCount() counts it, which keeps PageWriter's predicted numbers and the /AP references right.
  • PDF/A-1, PDF/A-2 and non-PDF/A output are unchanged. The inline file spec and the plain stream are still written for those.

The changes inside writeAnnotations() are two small branches, so the renumbering in #352 should rebase over them without trouble.

Tests

  • PdfaConformanceTest::testAttachmentsConform now runs at 2-B, 2-U, 3-B and 3-U. It also attaches a PHP file. It checks how many files each version embeds (PDF/A-2: 1, PDF/A-3: 3) and runs veraPDF on the result.
  • PDFA2Test::testPdfa3AssociatesAnnotationFile checks that the annotation's /FS and /AF point to the same file spec, and that the file spec carries /AFRelationship. It also checks that the stream carries the MIME /Subtype and that /AP still points to the appearance form.
  • PDFA2Test::testAnnotsListOnlyAnnotations gains a PDF/A-3 case, which covers the object count.
  • Without the fix, the new unit test and the 3-B/3-U conformance cases fail.

Gates

  • composer test: OK (3226 tests). The 5 skips are the existing generator-table tests, which need unpacked Unicode/HarfBuzz data.
  • vendor/bin/phpunit --group=conformance --fail-on-skipped: OK (12 tests)
  • composer cs: clean
  • phpstan: no errors
  • php -l under PHP 5.6: clean on every changed file

Left out

  • The MIME type is always application/octet-stream. It is not guessed from the file.
  • The attachment is not added to the catalog's /EmbeddedFiles name tree, because PDF/A-3 does not require it.

Fixes #347

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added bug Something isn't working create-upstream-pr labels Sep 23, 2026
@jakejackson1
jakejackson1 force-pushed the feature/pdfa-2-conformance branch from 8e388e9 to c93b66a Compare September 23, 2026 01:30
… veraPDF (#347)

Under PDF/A-3 the file of an <annotation file="..."> now goes through the
same writer as SetAssociatedFiles(): an indirect file specification with
/AFRelationship /Unspecified, named by the annotation's own /AF, and an
embedded file stream with a MIME /Subtype of application/octet-stream.
numberAnnotations() gives the file specification its own object number,
ahead of the stream's. PDF/A-1, PDF/A-2 and non-PDF/A output are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1

Copy link
Copy Markdown
Member Author

Rebased onto the rebased #330, which now includes #360's explicit annotation IDs and gravitypdf's AES-256 encryption.

  • annotationObjectCount() no longer exists. Under PDF/A-3, numberAnnotations() now gives an annotation's file two IDs: filespec, then file for its stream. The annotation's /FS and /AF name filespec.
  • writeAssociatedFile($file, $specId) starts both objects at their IDs, and is built from gravitypdf's newer version of that code: !empty() guards for optional keys, streamLength() for encryption, and the error message that falls back to the name. writeAssociatedFiles() passes n + 1, so SetAssociatedFiles() output is unchanged.
  • The commit message now describes the ID scheme rather than the removed count.

Gates:

  • full suite: 3345 tests, with no snapshot byte differences, and upstream's associated-file tests pass
  • --group=conformance --fail-on-skipped: 14 veraPDF cases, 3-B and 3-U attachments included
  • composer cs and PHPStan: clean
  • PHP 5.6 lint: clean

…e whole path

A file annotation's name kept everything after the last forward slash, so on
Windows the drive and directories stayed in the name (D:\a\x.php became
Dax.php). Strip up to the last slash or backslash.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 merged commit fe769ef into feature/pdfa-2-conformance Sep 23, 2026
29 checks passed
@jakejackson1
jakejackson1 deleted the fix/347-pdfa-3-annotation-attachments branch September 30, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant