@Test public void rootIsKeptChildIsStripped() { PDPage page1 = new PDPage(); PDPage page2 = new PDPage(); PDDocument document = new PDDocument(); document.addPage(page1); document.addPage(page2); PDDocumentOutline outlines = new PDDocumentOutline(); PDOutlineItem root = new PDOutlineItem(); root.setTitle("title"); root.setDestination(page1); PDOutlineItem child = new PDOutlineItem(); child.setTitle("child"); child.setDestination(page2); root.addFirst(child); outlines.addFirst(root); document.getDocumentCatalog().setDocumentOutline(outlines); mapping.addLookupEntry(document.getPage(0), new PDPage()); PDDocumentOutline outline = new PDDocumentOutline(); new OutlineDistiller(document).appendRelevantOutlineTo(outline, mapping); assertTrue(outline.hasChildren()); assertEquals(1, outline.getOpenCount()); }
public void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup) { requireNonNull(to, "Unable to merge relevant outline items to a null outline."); if (!pagesLookup.isEmpty()) { ofNullable(document.getDocumentCatalog().getDocumentOutline()).ifPresent(outline -> { for (PDOutlineItem child : outline.children()) { cloneNode(child, pagesLookup).ifPresent(c -> to.addLast(c)); } LOG.debug("Appended relevant outline items"); }); } }
OutlineDistiller { public void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup) { requireNonNull(to, "Unable to merge relevant outline items to a null outline."); if (!pagesLookup.isEmpty()) { ofNullable(document.getDocumentCatalog().getDocumentOutline()).ifPresent(outline -> { for (PDOutlineItem child : outline.children()) { cloneNode(child, pagesLookup).ifPresent(c -> to.addLast(c)); } LOG.debug("Appended relevant outline items"); }); } } }
OutlineDistiller { public void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup) { requireNonNull(to, "Unable to merge relevant outline items to a null outline."); if (!pagesLookup.isEmpty()) { ofNullable(document.getDocumentCatalog().getDocumentOutline()).ifPresent(outline -> { for (PDOutlineItem child : outline.children()) { cloneNode(child, pagesLookup).ifPresent(c -> to.addLast(c)); } LOG.debug("Appended relevant outline items"); }); } } OutlineDistiller(PDDocument document); }
OutlineDistiller { public void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup) { requireNonNull(to, "Unable to merge relevant outline items to a null outline."); if (!pagesLookup.isEmpty()) { ofNullable(document.getDocumentCatalog().getDocumentOutline()).ifPresent(outline -> { for (PDOutlineItem child : outline.children()) { cloneNode(child, pagesLookup).ifPresent(c -> to.addLast(c)); } LOG.debug("Appended relevant outline items"); }); } } OutlineDistiller(PDDocument document); void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup); }
OutlineDistiller { public void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup) { requireNonNull(to, "Unable to merge relevant outline items to a null outline."); if (!pagesLookup.isEmpty()) { ofNullable(document.getDocumentCatalog().getDocumentOutline()).ifPresent(outline -> { for (PDOutlineItem child : outline.children()) { cloneNode(child, pagesLookup).ifPresent(c -> to.addLast(c)); } LOG.debug("Appended relevant outline items"); }); } } OutlineDistiller(PDDocument document); void appendRelevantOutlineTo(PDOutlineNode to, LookupTable<PDPage> pagesLookup);  }