/** * Checks if page contains the specified annotation. * * @param annotation the {@link PdfAnnotation} to check. * @return {@code true} if page contains specified annotation and {@code false} otherwise. */ public boolean containsAnnotation(PdfAnnotation annotation) { for (PdfAnnotation a : getAnnotations()) { if (a.getPdfObject().equals(annotation.getPdfObject())) { return true; } } return false; }
private List<PdfLinkAnnotation> getLinkAnnotations(int pageNum, PdfDocument document) { List<PdfLinkAnnotation> linkAnnotations = new ArrayList<>(); List<PdfAnnotation> annotations = document.getPage(pageNum).getAnnotations(); for (PdfAnnotation annotation : annotations) { if (PdfName.Link.equals(annotation.getSubtype())) { linkAnnotations.add((PdfLinkAnnotation) annotation); } } return linkAnnotations; }
/** * This method removes all annotation entries from form fields associated with a given page. * * @param page to remove from. */ private void removeUnusedWidgetsFromFields(PdfPage page) { if (page.isFlushed()) { return; } List<PdfAnnotation> annots = page.getAnnotations(); for (PdfAnnotation annot : annots) { if (annot.getSubtype().equals(PdfName.Widget)) { ((PdfWidgetAnnotation) annot).releaseFormFieldFromWidgetAnnotation(); } } }
/** * Sets the /P and /A values corresponding to provided annotation, which is already added to a page. * * @param pdfAnnotation the annotation to be set * @param pdfDocument the corresponding document * @return this object wrapper */ public PdfTarget setAnnotation(PdfFileAttachmentAnnotation pdfAnnotation, PdfDocument pdfDocument) { PdfPage page = pdfAnnotation.getPage(); if (null == page) { throw new PdfException(PdfException.AnnotationShallHaveReferenceToPage); } else { put(PdfName.P, new PdfNumber(pdfDocument.getPageNumber(page))); put(PdfName.A, new PdfNumber(page.getAnnotations().indexOf(pdfAnnotation))); } return this; }
List<PdfAnnotation> annots = toPage.getAnnotations();
List<PdfAnnotation> annots = toPage.getAnnotations();
pageAnnotations = page.getAnnotations();
/** * Gets a {@link PdfPage} on which annotation is placed. * * @return {@link PdfPage} on which annotation is placed or null if annotation is not placed yet. */ public PdfPage getPage() { PdfIndirectReference annotationIndirectReference; if (page == null && (annotationIndirectReference = getPdfObject().getIndirectReference()) != null) { PdfDocument doc = annotationIndirectReference.getDocument(); PdfDictionary pageDictionary = getPageObject(); if (pageDictionary != null) { page = doc.getPage(pageDictionary); } else { for (int i = 1; i <= doc.getNumberOfPages(); i++) { PdfPage docPage = doc.getPage(i); if (!docPage.isFlushed()) { for (PdfAnnotation annot : docPage.getAnnotations()) { if (annotationIndirectReference.equals(annot.getPdfObject().getIndirectReference())) { page = docPage; break; } } } } } } return page; }
PdfPage page = new PdfPage(dictionary); copyInheritedProperties(page, toDocument); for (PdfAnnotation annot : getAnnotations()) { if (annot.getSubtype().equals(PdfName.Link)) { getDocument().storeLinkAnnotation(page, (PdfLinkAnnotation) annot);