1 回答
TA贡献2011条经验 获得超2个赞
首先,您必须将新值设置为字典中的URIannotationAction键:
if (annotationAction.get(PdfName.S).equals(PdfName.URI)) {
final PdfString destination = annotationAction.getAsString(PdfName.URI);
final String url = destination.toString();
System.out.println(url);
String updatedUrl = [... url changed to match the changed criteria ...];
annotationAction.put(PdfName.URI, new PdfString(updatedUrl));
}
之后,您必须通过应用保存更改而PdfStamper无需执行进一步操作:
final byte[] data = ByteStreams.toByteArray(istream);
pdfs.add(data);
final PdfReader reader = new PdfReader(data);
final PdfDictionary pageDictionary = reader.getPageN(36);
final PdfArray annotations = pageDictionary.getAsArray(PdfName.ANNOTS);
if (annotations != null && annotations.size() != 0) {
[...]
}
new PdfStamper(reader, new FileOutputStream(dir + name + "-new.pdf")).close();
添加回答
举报