Skip to content

Validate more PDF/A features with veraPDF and fix what it found - #1814

Merged
andreasrosdalw merged 3 commits into
LibrePDF:masterfrom
andreasrosdal:more-verapdf-tests
Dec 3, 2026
Merged

andreasrosdalw merged 3 commits into
LibrePDF:masterfrom
andreasrosdal:more-verapdf-tests

Conversation

@andreasrosdal

Copy link
Copy Markdown
Contributor

Description of the new Feature/Bugfix

Adds VeraPdfFeatureConformanceTest, which validates with veraPDF PDF/A documents that use features the existing veraPDF tests did not cover:

Feature Flavours
Accessible levels: tagged heading and paragraph PDF/A-1a, 2a, 3a
Bookmarks (nested outlines) on several pages 1b, 2b, 3b
Text annotation (sticky note) with an appearance 1b, 2b, 3b
Form: text field and check box 1b, 2b, 3b
Spot colour (Separation), gray, axial shading 1b, 2b, 3b
Images: GIF, indexed GIF, PNG with alpha, TIFF 1b, 2b, 3b
Fonts: WinAnsi, Identity-H (Greek, Cyrillic), symbol font, Thai 1b, 2b, 3b
TrueType font with Cp1250 encoding 2b, 3b (and rejected in 1b)
Pages of different sizes, landscape, page labels 1b, 2b, 3b
Attached XML file with AFRelationship 3b
Font that is not embedded, JavaScript rejected

The tests found these problems in OpenPDF, which this PR fixes:

  1. Annotations in PDF/A-2 and PDF/A-3 had no F key (veraPDF rule 6.3.2-1). PdfAnnotation set the print flag only for PDF/A-1. It now sets it for every PDF/A part.
  2. A TrueType font with an encoding other than WinAnsi or MacRoman, such as Cp1250, was not PDF/A-2 or PDF/A-3 compliant (rule 6.2.11.6-2). Its Encoding dictionary had a Differences array but no BaseEncoding. It now has /BaseEncoding /WinAnsiEncoding. Every code the font uses is listed in Differences, so the text renders the same.
  3. PDF/A-1 does not allow Differences at all for such a font (rule 6.3.7-1). OpenPDF wrote a non-compliant file. PdfWriter now throws a PdfXConformanceException that says to use BaseFont.IDENTITY_H.
  4. Document-level JavaScript was written into PDF/A files. PDF/A does not allow JavaScript. veraPDF does not report the JavaScript name tree, but the standard forbids it. PdfWriter.addJavaScript now throws a PdfXConformanceException in a PDF/A document.
  5. A check box could not be made PDF/A compliant. RadioCheckField.getField called setCheckType again, which reset the font to ZapfDingbats (not embedded) even when the caller had set an embedded font. It now only sets the caption, so a font set after setCheckType is kept.
  6. Test pollution: FontSubsetTest set an exhausted FixedSecureRandom on the cached Liberation Identity-H font, so later tests that took that font from the cache failed with an ArrayIndexOutOfBoundsException. It now uses an uncached font.

Not fixed here: OpenPDF does not draw an appearance for a text annotation, and PDF/A requires one. The test supplies the appearance, as a caller has to.

Related Issue: none

Unit-Tests for the new Feature/Bugfix

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Compatibilities Issues

No method signatures change. Behaviour changes, listed under Upgrade Notes in changelogs/4.0.0.md:

  • PdfWriter.addJavaScript throws a PdfXConformanceException in a PDF/A document.
  • In PDF/A-1, a simple TrueType font with an encoding other than WinAnsi or MacRoman throws a PdfXConformanceException.
  • RadioCheckField keeps a font set after setCheckType. Before, it always went back to ZapfDingbats.
  • Simple TrueType fonts with a Differences array also get /BaseEncoding /WinAnsiEncoding, also outside PDF/A.

Your real name

Andreas Røsdal

Testing details

./mvnw -pl openpdf-core test -Dtest=VeraPdfFeatureConformanceTest (35 tests). The full build ./mvnw install and ./mvnw checkstyle:check pass locally on Java 25.

🤖 Generated with Claude Code

andreasrosdal and others added 3 commits December 3, 2026 07:50
New veraPDF tests cover the accessible levels 1a, 2a and 3a, bookmarks,
a text annotation, form fields, spot colours, shadings, GIF, PNG and
TIFF images, fonts with several encodings, pages of different sizes
with page labels, and an attached file.

Fixes for what the tests found:
- Annotations in PDF/A-2 and PDF/A-3 get the F key with the print flag.
- A TrueType font with an encoding other than WinAnsi or MacRoman has
  the base encoding WinAnsiEncoding, as PDF/A-2 and PDF/A-3 require.
- PDF/A-1 rejects such a font, as it does not allow Differences.
- PDF/A rejects document-level JavaScript.
- RadioCheckField keeps a font that is set after setCheckType, so a
  check box can use an embedded font instead of ZapfDingbats.
- FontSubsetTest no longer sets an exhausted SecureRandom on the cached
  Liberation font that other tests use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 29 complexity · 4 duplication

Metric Results
Complexity 29
Duplication 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@andreasrosdalw
andreasrosdalw merged commit 94b52ec into LibrePDF:master Dec 3, 2026
11 of 12 checks passed
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants