最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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();
        }
发布评论

评论列表(0)

  1. 暂无评论