我正在寻找将外部链接更改为对附加文件的引用的可能性。我找到了一个样本来将外部链接更改为其他外部链接,但我需要一个指向附加文件的链接。
这是我发现的片段:
PDDocument doc = null;
try {
doc = PDDocument.load(pathToFile);
List allPages = doc.getDocumentCatalog().getAllPages();
for (int i = 0; i < allPages.size(); i++) {
PDPage page = (PDPage) allPages.get(i);
List annotations = page.getAnnotations();
for (int j = 0; j < annotations.size(); j++) {
PDAnnotation annot = (PDAnnotation) annotations.get(j);
if (annot instanceof PDAnnotationLink) {
PDAnnotationLink link = (PDAnnotationLink) annot;
PDAction action = link.getAction();
if (action instanceof PDActionURI) {
PDActionURI uri = (PDActionURI) action;
String oldURI = uri.getURI();
System.out.println(oldURI);
addToAttachment(oldURI, doc);
String newURI = "computer1.wmf";
System.out.println("Page " + (i + 1)
+ ": Replacing " + oldURI + " with "
+ newURI);
uri.setURI(newURI);
谢谢 最好的问候
马库斯