@Test public void testExecuteLevel2() throws IOException { SplitByOutlineLevelParameters parameters = setUpParameters(2, null); execute(parameters); testContext.assertTaskCompleted(); testContext.assertOutputSize(3).forEachPdfOutput(d -> { assertTrue(nonNull(d.getDocumentCatalog().getDocumentOutline())); }); }
@Test public void testExecuteLevel2DiscardOutline() throws IOException { SplitByOutlineLevelParameters parameters = setUpParameters(2, null); parameters.discardOutline(true); execute(parameters); testContext.assertTaskCompleted(); testContext.assertOutputSize(3).forEachPdfOutput(d -> { assertTrue(isNull(d.getDocumentCatalog().getDocumentOutline())); }); }
@Test public void extractWithOutline() throws IOException { setUpParametersWithOutline(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(3).forEachPdfOutput(d -> { assertTrue(nonNull(d.getDocumentCatalog().getDocumentOutline())); }); }
@Test public void resizeChangingAspectRatio() throws IOException { executeChangeOfPageSize(PageSize.LEGAL, customInput("pdf/test-pdf.pdf")); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); assertEqualsRect(PDRectangle.LEGAL, page.getMediaBox()); assertEqualsRect(PDRectangle.LEGAL, page.getCropBox()); }); }
@Test public void backPagesMultipleEncryptedInput() throws IOException { setUpParametersMultipleEncryptedInput(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertOutputSize(2).forEachPdfOutput(d -> assertEquals(10, d.getNumberOfPages())); } }
@Test public void extractWithDiscardOutline() throws IOException { setUpParametersWithOutline(); parameters.discardOutline(true); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(3).forEachPdfOutput(d -> { assertTrue(isNull(d.getDocumentCatalog().getDocumentOutline())); }); }
@Test public void splitWithOutline() throws IOException { setUpParameters(); parameters.addSource(largeOutlineInput()); parameters.addPage(1); parameters.addPage(2); parameters.addPage(3); execute(parameters); testContext.assertTaskCompleted(); testContext.assertOutputSize(4).forEachPdfOutput(d -> { assertTrue(nonNull(d.getDocumentCatalog().getDocumentOutline())); }); }
@Test public void aes256WithUserPassword() throws IOException { setUpParameters(PdfEncryption.AES_ENC_256); parameters.setUserPassword("1234"); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted("1234"); testContext.assertCreator().forEachPdfOutput(d -> { assertTrue(d.isEncrypted()); }); }
@Test public void testRotateSpecificPages() throws IOException { setUpRotateSpecificPages(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4).forEachPdfOutput(d -> assertEquals(90, d.getPage(2).getRotation())); }
private void asserts(int size) throws IOException { testContext.assertTaskCompleted(); testContext.assertOutputSize(size); testContext.forEachPdfOutput(d -> { assertEquals(Sejda.CREATOR, d.getDocumentInformation().getCreator()); assertFalse(d.isEncrypted()); assertEquals("Wrong output PDF version", PdfVersion.VERSION_1_6.getVersionString(), d.getVersion()); }); } }
@Test public void backPages() throws IOException { setUpParametersBackPageToEveryPage(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertOutputSize(1) .forEachPdfOutput(d -> assertEquals(8, d.getNumberOfPages())); }
@Test public void testExecuteEncrypted() throws IOException { setUpParametersEncrypted(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4) .forEachPdfOutput(d -> d.getPages().forEach(p -> assertEquals(180, p.getRotation()))); }
@Test public void imageWithExifOrientation() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.addSource(customNonPdfInputAsFileSource("image/with_exif_orientation.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getRotation(), 90); }); }
@Test public void testExecute() throws IOException { setUpDefaultParameters(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4) .forEachPdfOutput(d -> d.getPages().forEach(p -> assertEquals(180, p.getRotation()))); }
@Test public void noPageSelection() throws IOException { executeChangeOfPageSize(PageSize.A5, customInput("pdf/test-pdf.pdf")); testContext.forEachPdfOutput(d -> { // all pages have new size of A5 PDRectangle expected = PDRectangle.A5; for (PDPage page : d.getPages()) { assertEqualsRect(expected.rotate(page.getRotation()), page.getMediaBox()); assertEqualsRect(expected.rotate(page.getRotation()), page.getCropBox()); } }); }
@Test public void pageOrientationAuto() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getMediaBox(), PDRectangle.A4.rotate()); }); }
@Test public void noChanges() throws IOException { ResizePagesParameters parameters = new ResizePagesParameters(); parameters.addSource(customInput("pdf/test-pdf.pdf")); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); assertEqualsRect(PDRectangle.A4, page.getMediaBox()); assertEqualsRect(PDRectangle.A4, page.getCropBox()); }); }
@Test public void potrait() throws IOException { // A4 to A3 executeChangeOfPageSize(PageSize.A3, customInput("pdf/potrait.pdf"), customInput("pdf/potrait_by_rotation.pdf")); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); assertEqualsRect(PDRectangle.A3, page.getCropBox().rotate(page.getRotation())); assertEqualsRect(PDRectangle.A3, page.getMediaBox().rotate(page.getRotation())); }); }
@Test public void pageOrientationLandscape() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setPageOrientation(PageOrientation.LANDSCAPE); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getMediaBox(), PDRectangle.A4.rotate()); }); }
@Test public void landscape() throws IOException { executeChangeOfPageSize(PageSize.A5, customInput("pdf/landscape.pdf"), customInput("pdf/landscape_by_rotation.pdf")); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); assertEqualsRect(PDRectangle.A5.rotate(), page.getCropBox().rotate(page.getRotation())); assertEqualsRect(PDRectangle.A5.rotate(), page.getMediaBox().rotate(page.getRotation())); }); }