OutlineUtils { public static PDPageXYZDestination pageDestinationFor(PDPage page) { requireNotNullArg(page, "Cannot create a destination to a null page"); PDPageXYZDestination pageDest = new PDPageXYZDestination(); pageDest.setPage(page); PDRectangle cropBox = page.getCropBox(); switch (Rotation.getRotation(page.getRotation())) { case DEGREES_180: pageDest.setLeft((int) cropBox.getUpperRightX()); pageDest.setTop((int) cropBox.getLowerLeftY()); break; case DEGREES_270: pageDest.setLeft((int) cropBox.getUpperRightX()); pageDest.setTop((int) cropBox.getUpperRightY()); break; case DEGREES_90: pageDest.setLeft((int) cropBox.getLowerLeftX()); pageDest.setTop((int) cropBox.getLowerLeftY()); break; default: pageDest.setLeft((int) cropBox.getLowerLeftX()); pageDest.setTop((int) cropBox.getUpperRightY()); break; } return pageDest; } 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 pageDestinationForNull() { OutlineUtils.pageDestinationFor(null); }
@Test public void pageDestinationFor() { PDPage page = new PDPage(PDRectangle.A4); PDPageXYZDestination noRotation = OutlineUtils.pageDestinationFor(page); assertEquals(0, noRotation.getLeft()); assertEquals((int) PDRectangle.A4.getHeight(), noRotation.getTop()); page.setRotation(90); PDPageXYZDestination rotation90 = OutlineUtils.pageDestinationFor(page); assertEquals(0, rotation90.getLeft()); assertEquals(0, rotation90.getTop()); page.setRotation(180); PDPageXYZDestination rotation180 = OutlineUtils.pageDestinationFor(page); assertEquals((int) PDRectangle.A4.getWidth(), rotation180.getLeft()); assertEquals(0, rotation180.getTop()); page.setRotation(270); PDPageXYZDestination rotation270 = OutlineUtils.pageDestinationFor(page); assertEquals((int) PDRectangle.A4.getWidth(), rotation270.getLeft()); assertEquals((int) PDRectangle.A4.getHeight(), rotation270.getTop()); }