@Test public void addMargins() throws IOException { executeAddMargins(new Margins(0, 0, 2, 5), new PageRange(1, 3), regularInput()); // number of pages does not change testContext.assertPages(11).forEachPdfOutput(d -> { PDPage page = d.getPage(0); PDRectangle expected = new PDRectangle(0f, 0f, 595f + 360f, 842f + 144f); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); // contents is centered to create margins assertEquals("Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>", extractText(page, new Rectangle(415, 90, 415, 10))); assertEquals("Everyone is permitted to copy and distribute verbatim copies", extractText(page, new Rectangle(415, 102, 415, 10))); assertEquals("of this license document, but changing it is not allowed.", extractText(page, new Rectangle(415, 114, 415, 10))); page = d.getPage(3); expected = new PDRectangle(0f, 0f, 595f, 842f); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); assertEquals("You may charge", extractText(page, new Rectangle(65, 60, 91, 15))); }); }
@Test public void addUniformMargins() throws IOException { executeAddMargins(new Margins(1, 1, 1, 1), new PageRange(1, 3), regularInput()); // number of pages does not change testContext.assertPages(11).forEachPdfOutput(d -> { PDPage page = d.getPage(0); // page size is increased by 72 points in each direction PDRectangle expected = new PDRectangle(0f, 0f, 595f + 144f, 842f + 144f); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); // contents is centered to create margins assertEquals("Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>", extractText(page, new Rectangle(132, 164, 415, 10))); assertEquals("Everyone is permitted to copy and distribute verbatim copies", extractText(page, new Rectangle(132, 174, 415, 10))); assertEquals("of this license document, but changing it is not allowed.", extractText(page, new Rectangle(132, 184, 415, 10))); page = d.getPage(3); expected = new PDRectangle(0f, 0f, 595f, 842f); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); assertEquals("You may charge", extractText(page, new Rectangle(65, 60, 91, 15))); }); }