/** * This will set the previous URI action, in case it's needed. * * @return The previous URI. */ public PDActionURI getPreviousURI() { COSBase base = getCOSObject().getDictionaryObject("PA"); if (base instanceof COSDictionary) { return new PDActionURI((COSDictionary) base); } return null; }
/** * Default constructor. */ public PDActionURI() { setSubType(SUB_TYPE); }
PDActionURI action = new PDActionURI(); action.setURI("http://pdfbox.apache.org"); txtLink.setAction(action); annotations.add(txtLink);
System.out.println("Page " + pageNum + ":'" + urlText.trim() + "'=" + uri.getURI());
PDActionURI uri = (PDActionURI) action; String newURI = "www.test1.test1.com"; uri.setURI(newURI);
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);
PDActionURI uri = getActionURI(annotation); if (uri != null) { String link = uri.getURI(); if (link != null && link.trim().length() > 0) { xhtml.startElement("div", "class", "annotation");
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); }
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(); } }
break; case PDActionURI.SUB_TYPE: retval = new PDActionURI(action); break; case PDActionNamed.SUB_TYPE:
System.out.println("uri link:" + uri.getURI()); } else { if (action instanceof PDActionGoTo) {
/** * Default constructor. */ public PDActionURI() { setSubType(SUB_TYPE); }
PDActionURI uriAct = new PDActionURI(); uriAct.setURI(uri);
/** * This will set the previous URI action, in case it's needed. * * @return The previous URI. */ public PDActionURI getPreviousURI() { COSBase base = getCOSObject().getDictionaryObject("PA"); if (base instanceof COSDictionary) { return new PDActionURI((COSDictionary) base); } return null; }
System.out.println("Page " + pageNum + ":'" + urlText.trim() + "'=" + uri.getURI());
/** * Default constructor. */ public PDActionURI() { action = new COSDictionary(); setSubType(SUB_TYPE); }
PDActionURI uriAct = new PDActionURI(); uriAct.setURI(uri);
/** * This will set the previous URI action, in case it's needed. * * @return The previous URI. */ public PDActionURI getPreviousURI() { COSBase base = getCOSObject().getDictionaryObject("PA"); if (base instanceof COSDictionary) { return new PDActionURI((COSDictionary) base); } return null; }