Here is a sample Java program showing how to remove all link annotations present in a PDF document using Qoppa’s PDF library jPDFProcess:
// Load PDF document PDFDocument pdfDoc = new PDFDocument ("C:\\myfolder\\input.pdf", null); int pageCount = pdfDoc.getPageCount(); // loop through pages for (int i = 0; i < pageCount; i++) { try { PDFPage page = pdfDoc.getPage(i); Vector annots = page.getAnnotations(); // loop through annotations for (int j = 0; j < annots.size(); j++) { Annotation annot = (Annotation) annots.get(j); // if link then remove it if (annot instanceof Link) { page.removeAnnotation(annot); count++; } } } catch (PDFException e) { e.printStackTrace(); } } System.out.println("Number of links removed " + count); |