在sandbox.annotations.AddInReplyTo中,有一个示例只创建一个回复注释,我想添加两个以上的回复注释,参考示例,我想使用以下代码来停止两个回复注释。但是,创建的pdf可以在adobe acrobat pro或adobe reader中打开,但是回复注释的内容都是“Hello PDF 01”,replySticky2的“Hello PDF 02”无法显示,我的代码有问题吗?谢谢你的帮助!!!
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfDictionary page = reader.getPageN(1);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
PdfDictionary sticky = annots.getAsDict(0);
PdfArray stickyRect = sticky.getAsArray(PdfName.RECT);
PdfDictionary popup = annots.getAsDict(1);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
PdfWriter writer = stamper.getWriter();
Rectangle stickyRectangle = new Rectangle(
stickyRect.getAsNumber(0).floatValue(), stickyRect.getAsNumber(1).floatValue(),
stickyRect.getAsNumber(2).floatValue(), stickyRect.getAsNumber(3).floatValue()
);
PdfAnnotation replySticky = PdfAnnotation.createText(
writer, stickyRectangle, "Reply-01", "Hello PDF 01", true, "Comment");
replySticky.put(PdfName.IRT, annots.getAsIndirectObject(0));
stamper.addAnnotation(replySticky, 1);
PdfAnnotation replySticky2 = PdfAnnotation.createText(
writer, stickyRectangle, "Reply-02", "Hello PDF 02", true, "Comment");
replySticky2.put(PdfName.IRT, annots.getAsIndirectObject(0));
stamper.addAnnotation(replySticky2, 1);
stamper.close();
}