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