admin管理员组文章数量:1278983
I am trying to make my PDF generated by the PDFBox Java library accessible, and this requires tagging the embedded images in the file so that it can be read by a screen reader.
After referencing a few online resources, I wrote the following code that makes use of PDFMarkedContent to give an alternative text of the image.
However, when I run the generated document through the PDF accessibility checker from PAC, it still shows that the QR code image is untagged. How can I debug/add the alternative text to the QR code image correctly? Thanks!
Here is my code snippet for drawing the image on each page of the PDF
for (int pageidx = 0; pageidx < totalPage; pageidx++) {
PDPageContentStream contentstream = new PDPageContentStream(
doc, doc.getPage(pageidx), PDPageContentStream.AppendMode.APPEND, true);
PDPage page = doc.getPage(pageidx);
COSDictionary dict = new COSDictionary();
dict.setInt(COSName.MCID, mcid);
mcid++;
contentstream.beginMarkedContent(
COSName.IMAGE, PDPropertyList.create(dict));
contentstream.drawImage(image, x, y, px, py);
contentstream.endMarkedContent();
contentstream.close();
PDStructureTreeRoot root = new PDStructureTreeRoot();
doc.getDocumentCatalog().setStructureTreeRoot(root);
PDStructureElement parent =
new PDStructureElement(StandardStructureTypes.Figure, root);
root.appendKid(parent);
PDStructureElement element =
new PDStructureElement(StandardStructureTypes.Figure, parent);
element.setPage(doc.getPage(pageIndex));
element.setAlternateDescription("alternate");
dict.setString(COSName.ALT, "alternate");
PDMarkedContent marked = new PDMarkedContent(COSName.IMAGE, dict);
marked.addXObject(image);
element.appendKid(marked);
}
本文标签: javaHow to add alternative text to image in PDF using PDFBoxStack Overflow
版权声明:本文标题:java - How to add alternative text to image in PDF using PDFBox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741208753a2358677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论