/** * This will return a list of the annotations for this page. * * @return List of the PDAnnotation objects, never null. The returned list is backed by the * annotations COSArray, so any adding or deleting in this list will change the document too. * * @throws IOException If there is an error while creating the annotation list. */ public List<PDAnnotation> getAnnotations() throws IOException { return getAnnotations(new AnnotationFilter() { @Override public boolean accept(PDAnnotation annotation) { return true; } }); }
@Override public void createSignature(PDSignatureField pdSignatureField, PDPage page, String signerName) throws IOException { PDSignature pdSignature = new PDSignature(); PDAnnotationWidget widget = pdSignatureField.getWidgets().get(0); pdSignatureField.setValue(pdSignature); widget.setPage(page); page.getAnnotations().add(widget); if (!signerName.isEmpty()) { pdSignature.setName(signerName); } pdfStructure.setPdSignature(pdSignature); LOG.info("PDSignature has been created"); }
/** * Runs the engine on the current page. * * @throws IOException If there is an IO error while drawing the page. */ public void run() throws IOException { processPage(getPage()); for (PDAnnotation annotation : getPage().getAnnotations()) { showAnnotation(annotation); } }
/** * Draws the page to the requested context. * * @param g The graphics context to draw onto. * @param pageSize The size of the page to draw. * @throws IOException If there is an IO error while drawing the page. */ public void drawPage(Graphics g, PDRectangle pageSize) throws IOException { graphics = (Graphics2D) g; xform = graphics.getTransform(); this.pageSize = pageSize; setRenderingHints(); graphics.translate(0, pageSize.getHeight()); graphics.scale(1, -1); // adjust for non-(0,0) crop box graphics.translate(-pageSize.getLowerLeftX(), -pageSize.getLowerLeftY()); processPage(getPage()); for (PDAnnotation annotation : getPage().getAnnotations(annotationFilter)) { showAnnotation(annotation); } graphics = null; }
/** * * @param context the preflight context. * @param page the page to check. * @throws ValidationException */ protected void validateAnnotation(PreflightContext context, PDPage page) throws ValidationException { try { List<?> lAnnots = page.getAnnotations(); for (Object object : lAnnots) { if (object instanceof PDAnnotation) { COSDictionary cosAnnot = ((PDAnnotation) object).getCOSObject(); ContextHelper.validateElement(context, cosAnnot, ANNOTATIONS_PROCESS); } } } catch (ValidationException e) { throw e; } catch (IOException e) { // TODO IOException probably due to Encrypt throw new ValidationException("Unable to access Annotation", e); } }
/** * Update the StructParents and StructParent values in a PDPage. * * @param page the new page * @param structParentOffset the offset which should be applied */ private void updateStructParentEntries(PDPage page, int structParentOffset) throws IOException { if (page.getStructParents() >= 0) { page.setStructParents(page.getStructParents() + structParentOffset); } List<PDAnnotation> annots = page.getAnnotations(); List<PDAnnotation> newannots = new ArrayList<>(); for (PDAnnotation annot : annots) { if (annot.getStructParent() >= 0) { annot.setStructParent(annot.getStructParent() + structParentOffset); } newannots.add(annot); } page.setAnnotations(newannots); }
List<PDAnnotation> annotations = page.getAnnotations();
List<PDAnnotation> annotations = page.getAnnotations();
private void processAnnotations(PDPage imported) throws IOException { List<PDAnnotation> annotations = imported.getAnnotations(); for (PDAnnotation annotation : annotations) { if (annotation instanceof PDAnnotationLink) { PDAnnotationLink link = (PDAnnotationLink)annotation; PDDestination destination = link.getDestination(); if (destination == null && link.getAction() != null) { PDAction action = link.getAction(); if (action instanceof PDActionGoTo) { destination = ((PDActionGoTo)action).getDestination(); } } if (destination instanceof PDPageDestination) { // TODO preserve links to pages within the splitted result ((PDPageDestination) destination).setPage(null); } } // TODO preserve links to pages within the splitted result annotation.setPage(null); } } /**
List<PDAnnotation> annotations = page.getAnnotations();
for (PDAnnotation annotation : page.getAnnotations())
widget.setRectangle(rect); widget.setPage(page); page.getAnnotations().add(widget);
widget.setRectangle(rect); widget.setPage(page); page.getAnnotations().add(widget);
widget.setAppearanceState("Off"); // don't forget this, or button will be invisible widgets.add(widget); page.getAnnotations().add(widget);
for (PDAnnotation annotation: page.getAnnotations())
page1.getAnnotations().add(widget1); page2.getAnnotations().add(widget2);
for (PDAnnotation annotation : page.getAnnotations()) {
page.getAnnotations().add(checkbox.getWidgets().get(0)); acroForm.getFields().add(checkbox);
page.getAnnotations().add(widget);
List<PDAnnotation> annotations = page.getAnnotations(); PDAnnotationRubberStamp rubberStamp = new PDAnnotationRubberStamp(); rubberStamp.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET);