@Test public void extractPagesInvertedSelection() throws IOException { parameters = new ExtractPagesParameters(); parameters.setInvertSelection(true); parameters.addPageRange(new PageRange(7, 9)); parameters.addSource(customInput("pdf/test-pdf.pdf")); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); assertThat(parameters.getPages(11), is(new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 6, 10, 11)))); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(8); }
@Test public void extractRanges() throws IOException { setUpParametersPageRangesPages(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(3); }
@Test public void extractOddPages() throws IOException { setUpParametersOddPages(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(2); }
@Test public void extractEvenPagesFromEncrypted() throws IOException { setUpParametersEvenPagesEncrypted(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(2); }
@Test public void extractRangesMedium() throws IOException { setUpParametersPageRangesMediumFile(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_7).assertPages(19); }
@Test public void extractOptimized() throws IOException { setUpParametersToOptimize(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(1); }
@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 extractWrongPageRages() throws IOException { setUpParametersWrongPageRanges(); testContext.directoryOutputTo(parameters); TestListenerFailed failListener = TestListenerFactory.newFailedListener(); ThreadLocalNotificationContext.getContext().addListener(failListener); execute(parameters); assertTrue(failListener.isFailed()); }
@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 extractWithForms() throws IOException { parameters = new ExtractPagesParameters(); parameters.addPageRange(new PageRange(1, 1)); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); parameters.setCompress(true); parameters.setVersion(PdfVersion.VERSION_1_6); parameters.addSource(formInput()); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputSize(1); testContext.forEachPdfOutput(d -> { assertNotNull(d.getDocumentCatalog().getAcroForm()); }); } }
@Test public void extractMultipleFiles() throws IOException { parameters = new ExtractPagesParameters(); parameters.addPageRange(new PageRange(1, 2)); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); parameters.setCompress(true); parameters.setVersion(PdfVersion.VERSION_1_6); parameters.addSource(shortInput()); parameters.addSource(mediumInput()); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputSize(2); testContext.forEachPdfOutput(d -> { assertEquals(d.getNumberOfPages(), 2); }); }