String newURI = "http://pdfbox.apache.org"; System.out.println( "Page " + pageNum +": Replacing " + oldURI + " with " + newURI ); uri.setURI( newURI );
public static void changeURL(String originalPdf, String targetPdf, Map<String, String> urls ) { try (PDDocument doc = PDDocument.load(originalPdf)) { List<PDPage> allPages = doc.getDocumentCatalog().getAllPages(); for(PDPage page: allPages){ List annotations = page.getAnnotations(); for(PDAnnotation annot : page.getAnnotations()){ if (annot instanceof PDAnnotationLink) { PDAnnotationLink link = (PDAnnotationLink) annot; PDAction action = link.getAction(); if (action instanceof PDActionURI) { PDActionURI uri = (PDActionURI) action; String oldURL = uri.getURI(); for (Map.Entry<String, String> url : urls.entrySet()){ if (url.getKey().equals(oldURL)) { uri.setURI(url.getValue()); } } } } } } doc.save(targetPdf); } catch (IOException | COSVisitorException e) { e.printStackTrace(); } }
action.setURI("http://pdfbox.apache.org"); txtLink.setAction(action); annotations.add(txtLink);
PDActionURI uri = (PDActionURI) action; String newURI = "www.test1.test1.com"; uri.setURI(newURI);
String newURI = "http://pdfbox.apache.org"; System.out.println( "Page " + pageNum +": Replacing " + oldURI + " with " + newURI ); uri.setURI( newURI );
private PDRectangle addAnnotationLinkRectangle(final float x, final float y, final float width, final float height, final String linkURL) throws IOException { final float startingY = checkYAndSwitchPage(y, height); final PDAnnotationLink txtLink = new PDAnnotationLink(); final PDRectangle position = new PDRectangle(); position.setLowerLeftX(x); position.setLowerLeftY(startingY); position.setUpperRightX(x + width); position.setUpperRightY(startingY + height); txtLink.setRectangle(position); final PDActionURI action = new PDActionURI(); action.setURI(linkURL); txtLink.setAction(action); currentPage.getAnnotations().add(txtLink); return new PDRectangle(x, startingY, width, height); }
uriAct.setURI(uri);
uriAct.setURI(uri);
uriAct.setURI(uri);
PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary(); borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE); borderULine.setWidth(1); PDAnnotationLink txtLink = new PDAnnotationLink(); txtLink.setBorderStyle(borderULine); // Set the rectangle containing the link textWidth = font.getStringWidth("Click here") / 1000 * xscale; position = new PDRectangle(); position.setLowerLeftX(...); position.setLowerLeftY(...); position.setUpperRightX(...); position.setUpperRightY(...); txtLink.setRectangle(position); // add an action PDActionURI action = new PDActionURI(); action.setURI("http://pdfbox.apache.org"); txtLink.setAction(action); annotations.add(txtLink);
action.setURI(currFol.getName() + "/" + currDoc.getName());
action.setURI("http://pdfbox.apache.org"); txtLink.setAction(action); annotations.add(txtLink);