java - PDFBox Free Text Annotation content is not visible on macos - Stack Overflow

I am trying to draw a free text annotation using rich content in pdfbox. The output file properly shows

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();
        }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745645262a4637931.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信