在pdfbox中添加对评论的回复

时间:2018-07-16 05:52:43

标签: java annotations 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();
}

0 个答案:

没有答案