PdfOutline implements Serializable { public void removeOutline() { if (!pdfDoc.hasOutlines() || isOutlineRoot()) { pdfDoc.getCatalog().remove(PdfName.Outlines); return; } PdfOutline parent = this.parent; List<PdfOutline> children = parent.children; children.remove(this); PdfDictionary parentContent = parent.content; if (children.size() > 0) { parentContent.put(PdfName.First, children.get(0).content); parentContent.put(PdfName.Last, children.get(children.size() - 1).content); } else { parent.removeOutline(); return; } PdfDictionary next = content.getAsDictionary(PdfName.Next); PdfDictionary prev = content.getAsDictionary(PdfName.Prev); if (prev != null) { if (next != null) { prev.put(PdfName.Next, next); next.put(PdfName.Prev, prev); } else { prev.remove(PdfName.Next); } } else if (next != null) { next.remove(PdfName.Prev); } } PdfOutline(String title, PdfDictionary content, PdfDocument pdfDocument);   PdfOutline(String title, PdfDictionary content, PdfOutline parent);   PdfOutline(PdfDocument doc); String getTitle(); void setTitle(String title); void setColor(Color color); void setStyle(int style); PdfDictionary getContent(); List<PdfOutline> getAllChildren(); PdfOutline getParent(); PdfDestination getDestination(); void addDestination(PdfDestination destination); void addAction(PdfAction action); void setOpen(boolean open); PdfOutline addOutline(String title, int position); PdfOutline addOutline(String title); PdfOutline addOutline(PdfOutline outline); void removeOutline(); static int FLAG_ITALIC; static int FLAG_BOLD; }
@Test public void removeAllOutlinesTest() throws IOException, InterruptedException { String filename = "iphone_user_guide_removeAllOutlinesTest.pdf"; String input = sourceFolder + "iphone_user_guide.pdf"; String output = destinationFolder + "cmp_" + filename; String cmp = sourceFolder + "cmp_" + filename; PdfReader reader = new PdfReader(input); PdfWriter writer = new PdfWriter(output); PdfDocument pdfDocument = new PdfDocument(reader, writer); pdfDocument.getOutlines(true).removeOutline(); pdfDocument.close(); Assert.assertNull(new CompareTool().compareByContent(output, cmp, destinationFolder, "diff_")); }