I’m currently working on generating a PDF file that is PDF/UA-compliant. My main goal is to ensure that it meets accessibility standards and passes the PAC (PDF Accessibility Checker) tool.
The problem I’m facing is that the PAC checker consistently flags my PDF with an error saying: "Test Object Not Tagged." This suggests that the necessary tagging might be missing or improperly implemented, but I’m not sure what I’m missing to address this.
I’ve made sure to:
Define document structure elements
Use the right tags in the PDF content generation code
Apply what I believe to be the correct metadata and settings for accessibility
However, it seems I’m still missing something fundamental for the tagging to be recognized. What steps might I be overlooking to achieve the proper tagging in a PDF for PDF/UA compliance?
Any insights on where I might be going wrong, or pointers on critical tagging elements to check, would be greatly appreciated
. Below is my code.
public void newPdf() {
int mcidCounter = 0; // Starten bei 0
int structParentCounter = 0; // Starten bei 0
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
// Setzen des StructParents-Eintrags auf der Seite
page.setStructParents(structParentCounter); // structParentCounter ist 0
PDPageContentStream contentStream = new PDPageContentStream(document, page);
PDType0Font font = loadFont(FontEnum.BUNDES_SANS_WEB_REGULAR, document);
// Schriftart den Ressourcen der Seite hinzufügen
PDResources resources = page.getResources();
if (resources == null) {
resources = new PDResources();
page.setResources(resources);
}
resources.add(font);
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDStructureTreeRoot structureTreeRoot = new PDStructureTreeRoot();
catalog.setStructureTreeRoot(structureTreeRoot);
catalog.setLanguage("de-DE"); // Setzt die Dokumentensprache auf Deutsch
PDMarkInfo markInfo = new PDMarkInfo();
markInfo.setMarked(true);
catalog.setMarkInfo(markInfo);
// Erstellen des Dokument-Strukturelements
PDStructureElement documentElement = new PDStructureElement(StandardStructureTypes.DOCUMENT, structureTreeRoot);
structureTreeRoot.appendKid(documentElement);
// Erstellen des Absatz-Strukturelements
PDStructureElement paragraphElement = new PDStructureElement(StandardStructureTypes.P, documentElement);
paragraphElement.setPage(page);
documentElement.appendKid(paragraphElement);
// Vorbereiten des Markierungsinhalts mit MCID
COSDictionary markedContentDictionary = new COSDictionary();
markedContentDictionary.setInt(COSName.MCID, mcidCounter);
// Beginnen des markierten Inhalts
contentStream.beginMarkedContent(COSName.P, PDPropertyList.create(markedContentDictionary));
contentStream.setFont(font, 12);
contentStream.beginText();
contentStream.newLineAtOffset(50, 700);
contentStream.showText("Hallo Welt");
contentStream.endText();
contentStream.endMarkedContent();
// Schließen des Inhaltsstroms
contentStream.close();
// Erstellen des Parent Trees und Verknüpfen mit dem Strukturelement
COSDictionary parentTreeRoot = new COSDictionary();
PDNumberTreeNode parentTree = new PDNumberTreeNode(parentTreeRoot, COSBase.class);
// Mapping von StructParent zu Strukturelement
Map<Integer, COSObjectable> parentTreeMap = new HashMap<>();
parentTreeMap.put(structParentCounter, paragraphElement);
parentTree.setNumbers(parentTreeMap);
structureTreeRoot.setParentTree(parentTree);
// Dokument speichern
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
document.save(outputStream);
byte[] pdfBytes = outputStream.toByteArray();
document.close();
Path actualPath = Path.of("src/test/resources/pdf/small_test.pdf");
Files.write(actualPath, pdfBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
}
You need to sign in to view this answers
Leave feedback about this