PdfWriter writes non-conformant `/MarkInfo << /Marked true >>` instead of `/MarkInfo << /Tagged true >>` (ISO 32000-1)
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
Research direction
In PdfName, the MARKED constant is defined, and PdfWriter.getCatalog(PdfIndirectReference) uses it when building the catalog’s MarkInfo dictionary. Read those two locations, then check the generated catalog after calling PdfWriter.setTagged(). Done when it contains /Tagged true as specified, rather than /Marked true.
Written by the indexing model from the issue text.
Description
Describe the bug
When a document is marked as tagged via PdfWriter.setTagged(), the catalog of the generated PDF contains:
/MarkInfo << /Marked true >>
According to ISO 32000-1:2008 §14.8.2 (Mark Info), the entry that marks a tagged document in the MarkInfo dictionary is Tagged:
Tagged (Optional; PDF 1.4) — A boolean indicating whether the document contains semantic information that aids accessibility (true) or not (false).
The name Marked is not defined by the specification. The structural tree (StructTreeRoot) is generated correctly, but the flag that tells viewers and assistive technology the document is tagged is invalid — so documents produced with setTagged() are not recognized as tagged by PDF validators and PDF/UA (ISO 14289) conformance checks. In practice this makes it impossible to produce conformant tagged / PDF/UA documents with this library.
org.openpdf.text.pdf.PdfName (line 1677):
public static final PdfName MARKED = new PdfName("Marked");
consumed by org.openpdf.text.pdf.PdfWriter.getCatalog(PdfIndirectReference) (line 1056):
PdfDictionary mi = new PdfDictionary();
mi.put(PdfName.MARKED, PdfBoolean.PDFTRUE);
...
catalog.put(PdfName.MARKINFO, mi);
The value appears to have been carried over from iText 2.1.x, where the same non-conformant constant exists.
To Reproduce
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("out.pdf"));
writer.setTagged();
doc.open();
doc.add(new Paragraph("Hello tagged PDF"));
doc.close();
Expected behavior
/MarkInfo << /Tagged true >>
Suggested fix
public static final PdfName MARKED = new PdfName("Tagged");
System
- OS: Windows
- Used font: Helvetica
- OpenPDF version: 3.0.5
Additional context
PdfName.MARKED has exactly two occurrences in the 3.0.5 source: its definition and PdfWriter.getCatalog — nothing in the library ever reads this entry back, so changing the constant to the spec value "Tagged" only affects newly written documents (and documents written with /Marked were non-conformant to begin with, so there is no conformant reading behaviour to preserve). Suggested one-line fix:
public static final PdfName MARKED = new PdfName("Tagged");
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 714
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from LibrePDF/OpenPDF
-
IndexOutOfBoundsException in PdfReaderPossibly taken @andreasrosdalw claimed this 91 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
`PdfSmartCopy` can take effectively unbounded time on nested shared Form XObjectsPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
Difficulty 4/5 1-2 days Newbie friendliness 45/100
All issues in LibrePDF/OpenPDF
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/rocketmq-dashboard#7361 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ballerina-platform/static-code-analysis-tool#140 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
atomityhq/blog-cms#82 · 1 comment ·
Maintainers usually reply within 1 day
-
ready-for-triage triaged
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
RedHatInsights/notifications-backend#5080 · 2 comments ·
Maintainers usually reply within 1 day