OutlineUtils { public static PDPageDestination clonePageDestination(PDPageDestination dest, PDPage destPage) { requireNotNullArg(dest, "Cannot clone a null destination"); try { PDDestination clonedDestination = PDDestination.create(dest.getCOSObject().duplicate()); if (clonedDestination instanceof PDPageDestination) { ((PDPageDestination) clonedDestination).setPage(destPage); return (PDPageDestination) clonedDestination; } } catch (IOException e) { LOG.warn("Unable to clone page destination", e); } PDPageXYZDestination ret = new PDPageXYZDestination(); ret.setPage(destPage); return ret; } private  OutlineUtils(); static Set<Integer> getOutlineLevelsWithPageDestination(PDDocument document); static Optional<PDPageDestination> toPageDestination(PDOutlineItem current, PDDocumentCatalog catalog); static PDPageXYZDestination pageDestinationFor(PDPage page); static PDPageDestination clonePageDestination(PDPageDestination dest, PDPage destPage); static PDPage resolvePageDestination(PDPageDestination destination, PDDocument document); static void copyOutlineDictionary(PDOutlineItem from, PDOutlineItem to); static List<OutlineItem> getFlatOutline(PDDocument document); static void printOutline(PDDocument document);  }
@Test(expected = IllegalArgumentException.class) public void clonePageDestinationNullDest() { OutlineUtils.clonePageDestination(null, new PDPage()); }
@Test public void clonePageDestinationSameType() { PDPage origin = new PDPage(); PDPage newPage = new PDPage(); PDPageFitHeightDestination destination = new PDPageFitHeightDestination(); destination.setPage(origin); destination.setLeft(20); PDPageDestination cloned = OutlineUtils.clonePageDestination(destination, newPage); assertThat(cloned, is(instanceOf(PDPageFitHeightDestination.class))); assertEquals(newPage, cloned.getPage()); assertEquals(20, ((PDPageFitHeightDestination) cloned).getLeft()); }