admin管理员组文章数量:1387428
I'm using PDFBox 3.0.2 to generate an accessible PDF with structured elements, but I am failing the PAC (PDF Accessibility Checker) test because I cannot properly associate a PDAnnotationLink with its PDStructureElement.
Here's the relevant code I am using:
// Step 1: Create structure element
PDStructureElement element = new PDStructureElement(StandardStructureTypes.LINK, parentElement);
// Step 2: Create the accessible link annotation
PDAnnotationLink link = new PDAnnotationLink();
link.setPage(page);
PDRectangle linkRect = new PDRectangle(100, 100, 120, 15);
link.setRectangle(linkRect );
link.setContents(layoutInfo.text());
link.getCOSObject().setBoolean("IsMap", false);
PDObjectReference objRef = new PDObjectReference();
objRef.setReferencedObject(link);
element.appendKid(objRef);
link.setStructParent(structParentCounter);
page.getAnnotations().add(link);
PDActionGoTo action = new PDActionGoTo();
PDPageXYZDestination destination = new PDPageXYZDestination();
destination.setPage(page);
destination.setTop((int) 83);
action.setDestination(destination);
link.setAction(action);
page.getAnnotations().add(link);
// Step 3: Associate the marked content reference with the structure element
PDMarkedContentReference mcr = new PDMarkedContentReference();
mcr.setMCID(mcidCounter);
element.appendKid(mcr);
// Step 4: Define marked content properties
COSDictionary markedContentDictionary = new COSDictionary();
markedContentDictionary.setInt(COSName.MCID, mcidCounter);
markedContentDictionary.setString(COSName.CONTENTS, "*");
try {
PDPageContentStream contentStream = getCurrentLayoutState().contentStream();
contentStream.setLeading(LINIE_SPACING);
// Step 5: Begin marked content
contentStream.beginMarkedContent(COSName.getPDFName("link"), PDPropertyList.create(markedContentDictionary ));
contentStream.beginText();
contentStream.newLineAtOffset(100, 100);
contentStream.showText("*");
contentStream.endText();
contentStream.endMarkedContent();
// Step 6: Move to next MCID
mcidCounter++;
structureElementArray.add(element);
} catch (IOException e) {
e.printStackTrace();
}
Even though I have structured the content, PAC still does not recognize the PDAnnotationLink as part of the structure. The annotation is visible in the PDF, but it does not appear as part of the Link structure in accessibility tools.
How can I properly associate PDAnnotationLink with its corresponding PDStructureElement so that PAC recognizes the link annotation as part of the structure?
Additional notes
- PDFBox Version: 3.0.2
- Goal: PDF/UA Compliance
- Issue: PDAnnotationLink not connected to PDStructureElement
What I've tried: using appendKid(), PDMarkedContentReference, and setting a COSDictionary, but the link is still not detected correctly.
版权声明:本文标题:java - How to properly associate PDAnnotationLink with PDStructureElement for PDFUA compliance? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744569385a2613249.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论