PdfScaler { public void scale(PDDocument doc, double scale) throws TaskIOException { scale(doc, doc.getPages(), scale); } PdfScaler(ScaleType type); void scalePages(PDDocument doc); void scalePages(PDDocument doc, Iterable<PDPage> pages, PDRectangle targetBox); void changePageSize(PDDocument doc, Iterable<PDPage> pages, PDRectangle desiredPageSize); void scale(PDDocument doc, double scale); void scale(PDDocument doc, PDPage page, double scale); void scale(PDDocument doc, Iterable<PDPage> pages, double scale); void changePageSize(PDDocument doc, PDPage page, PDRectangle desiredPageSize); static void margin(PDDocument doc, Iterable<PDPage> pages, Margins margins);  }
@Test public void shrinkContentNoBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PdfScaler scaler = new PdfScaler(ScaleType.CONTENT); scaler.scale(document, 0.5); PDPage page = document.getPage(0); assertEquals(new PDRectangle(0, 0, 595, 842), page.getMediaBox()); assertEquals(new PDRectangle(0, 0, 595, 842), page.getCropBox()); assertEquals(new PDRectangle(148.75f, 210.5f, 297.5f, 421f), page.getArtBox()); assertEquals(new PDRectangle(148.75f, 210.5f, 297.5f, 421f), page.getBleedBox()); assertEquals(new PDRectangle(148.75f, 210.5f, 297.5f, 421f), page.getTrimBox()); } }
@Test public void shrinkContentYesBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PDPage page = document.getPage(0); PDRectangle yesBox = new PDRectangle(0, 0, 200, 400); PDRectangle cropBox = new PDRectangle(0, 0, 400, 800); page.setCropBox(cropBox); page.setArtBox(yesBox); page.setTrimBox(yesBox); page.setBleedBox(yesBox); PdfScaler scaler = new PdfScaler(ScaleType.CONTENT); scaler.scale(document, 0.5); assertEquals(new PDRectangle(0, 0, 595, 842), page.getMediaBox()); assertEquals(cropBox, page.getCropBox()); assertEquals(new PDRectangle(150, 300, 100, 200), page.getArtBox()); assertEquals(new PDRectangle(150, 300, 100, 200), page.getBleedBox()); assertEquals(new PDRectangle(150, 300, 100, 200), page.getTrimBox()); } }
@Test public void expandContentNoBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PdfScaler scaler = new PdfScaler(ScaleType.CONTENT); scaler.scale(document, 1.5); PDPage page = document.getPage(0); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getMediaBox()); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getCropBox()); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getArtBox()); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getBleedBox()); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getTrimBox()); } }
@Test public void expandContentYesBoxesOverflow() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PDPage page = document.getPage(0); PDRectangle yesBox = new PDRectangle(0, 0, 200, 400); PDRectangle cropBox = new PDRectangle(0, 0, 400, 800); page.setCropBox(cropBox); page.setArtBox(yesBox); page.setTrimBox(yesBox); page.setBleedBox(yesBox); PdfScaler scaler = new PdfScaler(ScaleType.CONTENT); scaler.scale(document, 2.5); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getMediaBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getCropBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getArtBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getBleedBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getTrimBox()); } }
@Test public void expandContentYesBoxesNoOverflow() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PDPage page = document.getPage(0); PDRectangle yesBox = new PDRectangle(0, 0, 200, 400); PDRectangle cropBox = new PDRectangle(0, 0, 400, 800); page.setCropBox(cropBox); page.setArtBox(yesBox); page.setTrimBox(yesBox); page.setBleedBox(yesBox); PdfScaler scaler = new PdfScaler(ScaleType.CONTENT); scaler.scale(document, 1.5); assertEquals(new PDRectangle(0, 0, 595f, 842), page.getMediaBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getCropBox()); assertEquals(new PDRectangle(50, 100, 300, 600), page.getArtBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getBleedBox()); assertEquals(new PDRectangle(0, 0, 400, 800), page.getTrimBox()); } }
@Test public void shrinkPageNoBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PdfScaler scaler = new PdfScaler(ScaleType.PAGE); scaler.scale(document, 0.5); PDPage page = document.getPage(0); PDRectangle expected = new PDRectangle(0f, 0f, 297.5f, 421f); assertEquals(expected, page.getMediaBox()); assertEquals(expected, page.getCropBox()); assertEquals(expected, page.getArtBox()); assertEquals(expected, page.getBleedBox()); assertEquals(expected, page.getTrimBox()); } }
@Test public void expandPageNoBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PdfScaler scaler = new PdfScaler(ScaleType.PAGE); scaler.scale(document, 1.5); PDPage page = document.getPage(0); PDRectangle expected = new PDRectangle(0, 0, 892.5f, 1263f); assertEquals(expected, page.getMediaBox()); assertEquals(expected, page.getCropBox()); assertEquals(expected, page.getTrimBox()); assertEquals(expected, page.getArtBox()); assertEquals(expected, page.getBleedBox()); } }
@Test public void expandPagesYesBoxes() throws IOException, TaskIOException { try (PDDocument document = PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream("pdf/one_page.pdf")))) { PDPage page = document.getPage(0); PDRectangle yesBox = new PDRectangle(0, 0, 200, 400); PDRectangle cropBox = new PDRectangle(0, 0, 400, 800); page.setCropBox(cropBox); page.setArtBox(yesBox); page.setTrimBox(yesBox); page.setBleedBox(yesBox); PdfScaler scaler = new PdfScaler(ScaleType.PAGE); scaler.scale(document, 1.5); assertEquals(new PDRectangle(0, 0, 892.5f, 1263f), page.getMediaBox()); assertEquals(new PDRectangle(0, 0, 600, 1200), page.getCropBox()); assertEquals(new PDRectangle(0, 0, 300, 600), page.getArtBox()); assertEquals(new PDRectangle(0, 0, 300, 600), page.getBleedBox()); assertEquals(new PDRectangle(0, 0, 300, 600), page.getTrimBox()); } }