首页 > 解决方案 > 在 pdfbox 中添加对评论的回复

问题描述

我想将回复添加到我为注释输入的评论中。但是我写的代码没有回复,只有注释和评论。我错过了什么?我正在分享我的代码。另外我想添加注释的创建日期,我应该怎么做?提前致谢。

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    // Loading an existing document
    File file = new File("ABC.pdf");
    PDDocument document = PDDocument.load(file);
    System.out.println("PDF loaded.");

    PDPage page = document.getPage(0);
    List<PDAnnotation> annotations = page.getAnnotations();

    PDColor color = new PDColor(new float[] {255f, 0, 0}, PDDeviceRGB.INSTANCE);
    PDBorderStyleDictionary thickness = new PDBorderStyleDictionary();
    thickness.setWidth((float)2);

    PDAnnotationSquareCircle rectangle = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
    rectangle.setColor(color);
    rectangle.setBorderStyle(thickness);

    PDRectangle points = new PDRectangle();

    points.setLowerLeftX((float) 100);
    points.setLowerLeftY((float) 100);
    points.setUpperRightX((float) 300);
    points.setUpperRightY((float) 300);
    rectangle.setContents("Rectangle");
    rectangle.setRectangle(points);
    rectangle.getCOSObject().setString(COSName.T, "XYZ");

    PDAnnotationMarkup reply = new PDAnnotationMarkup();
    reply.getCOSObject().setName(COSName.SUBTYPE, PDAnnotationMarkup.RT_REPLY);
    reply.setContents("Hello 2");
    reply.setReplyType("R");
    reply.setInReplyTo(rectangle);

    annotations.add(rectangle);
    System.out.println("Rectangle is added.");

    // Save the file
    document.save(file);

    // Close the document
    document.close();
}

标签: javaannotationspdfbox

解决方案


推荐阅读