admin管理员组文章数量:1434929
I am trying to draw a free text annotation using rich content in pdfbox. The output file properly shows the annotation on Acrobat Reader. If I open it in the MacOS preview, the content of the free text annotation is hidden. Then, I tried slightly moving the annotation in Acrobat Reader and saved the file. After that, I could see the proper rendering on MacOS preview. It seems like Acrobat Reader is doing some sort of repair of the PDF. Can someone help me to figure out the issue in this code?
try (PDDocument document = new PDDocument()) {
// Add a new page
PDPage page = new PDPage();
document.addPage(page);
// Define the rectangle area where the annotation will appear
PDRectangle rect = new PDRectangle(100, 600, 100, 100);
// Create a FreeText annotation
PDAnnotationFreeText freeText = new PDAnnotationFreeText();
freeText.setRectangle(rect);
String content = "Your styled text here";
String richContent = "<body xmlns=\"\">" +
"<p style=\"font-family:Helvetica;font-size:20pt;color:#FF0000;text-align:right;\">" +
content + "</p></body>";
freeText.setRichContents(richContent);
page.getAnnotations().add(freeText);
document.save("output.pdf");
System.out.println("FreeText annotation created successfully.");
} catch (IOException e) {
e.printStackTrace();
}
本文标签: javaPDFBox Free Text Annotation content is not visible on macosStack Overflow
版权声明:本文标题:java - PDFBox Free Text Annotation content is not visible on macos - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745645261a2668096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论