@Test public void testWithMatchingText() throws IOException { ExtractByOutlineParameters parameters = setUpParameters(3, "(Using)+.+"); parameters.setIncludePageAfter(true); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputSize(3).assertPages("1_Using Profiles.pdf", 2) .assertPages("2_Using Profiles by OS.pdf", 2).assertPages("3_Using internal Repositories.pdf", 2); }
@Test public void testWithMatchingTextAndOptimization() throws IOException { ExtractByOutlineParameters parameters = setUpParameters(3, "(Using)+.+"); parameters.setOptimizationPolicy(OptimizationPolicy.YES); parameters.setIncludePageAfter(true); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputSize(3).assertPages("1_Using Profiles.pdf", 2) .assertPages("2_Using Profiles by OS.pdf", 2).assertPages("3_Using internal Repositories.pdf", 2); }
@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 testIncludingPageAfterOff() throws IOException { ExtractByOutlineParameters parameters = setUpParameters(1, "pdf/payslip_with_bookmarks.pdf", null); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputContainsFilenames("1_Employee One.pdf", "3_Employee Three.pdf", "2_Employee Two.pdf"); testContext.assertOutputSize(3); testContext.assertPages("1_Employee One.pdf", 1); }
@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 testVersionPrefixAndCreatorAreApplied() throws IOException { setUpParametersWithVersionPrefixAndCompressionSpecified(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4).assertVersion(PdfVersion.VERSION_1_6); }
@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 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 testIncludingPageAfterOn() throws IOException { ExtractByOutlineParameters parameters = setUpParameters(1, "pdf/payslip_with_bookmarks.pdf", null); parameters.setIncludePageAfter(true); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertOutputContainsFilenames("1_Employee One.pdf", "3_Employee Three.pdf", "2_Employee Two.pdf"); testContext.assertOutputSize(3); testContext.assertPages("1_Employee One.pdf", 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 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 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 testRotateSpecificPages() throws IOException { setUpRotateSpecificPages(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4).forEachPdfOutput(d -> assertEquals(90, d.getPage(2).getRotation())); }
@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 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 testExecutePages() throws IOException { setUpParameters(); testContext.pdfOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(1).forPdfOutput(d -> { COSBase names = d.getDocumentCatalog().getNames().getEmbeddedFiles().getCOSObject().getItem(COSName.NAMES); assertThat(names, instanceOf(COSArray.class)); assertEquals(6, ((COSArray) names).size()); assertNotNull(d.getDocumentCatalog().getCOSObject().getItem(COSName.getPDFName("Collection"))); }); }
@Test public void withEncryptedInput() throws IOException { AlternateMixMultipleInputParameters parameters = new AlternateMixMultipleInputParameters(); parameters.addInput(new PdfMixInput(encryptedInput())); parameters.addInput(new PdfMixInput(stronglyEncryptedInput(), true, 3)); setUpParameters(parameters); testContext.pdfOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(8).assertVersion(PdfVersion.VERSION_1_5); }
@Test public void withStandardInput() throws IOException { AlternateMixMultipleInputParameters parameters = new AlternateMixMultipleInputParameters(); parameters.addInput(new PdfMixInput(shortInput())); parameters.addInput(new PdfMixInput(shortInput(), true, 3)); setUpParameters(parameters); testContext.pdfOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(8).assertVersion(PdfVersion.VERSION_1_5); }
@Test public void testExecute() throws IOException { setUpParameters(); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertVersion(PdfVersion.VERSION_1_6).assertPages(4).forPdfOutput(d -> { PDTransition trans = d.getPage(0).getTransition(); assertEquals(PDTransitionStyle.Box.toString(), trans.getStyle()); assertEquals(PDTransitionMotion.O.toString(), trans.getMotion()); assertNull(d.getPage(1).getTransition()); assertNull(d.getPage(2).getTransition()); assertNull(d.getPage(3).getTransition()); }); }