PdfSplitter { public List<PdfDocument> extractPageRanges(List<PageRange> pageRanges) { List<PdfDocument> splitDocuments = new ArrayList<>(); for (PageRange currentPageRange : pageRanges) { PdfDocument currentPdfDocument = createPdfDocument(currentPageRange); splitDocuments.add(currentPdfDocument); pdfDocument.copyPagesTo(currentPageRange.getQualifyingPageNums(pdfDocument.getNumberOfPages()), currentPdfDocument); } return splitDocuments; } PdfSplitter(PdfDocument pdfDocument); void setEventCountingMetaInfo(IMetaInfo metaInfo); void setPreserveTagged(boolean preserveTagged); void setPreserveOutlines(boolean preserveOutlines); List<PdfDocument> splitBySize(long size); void splitByPageNumbers(List<Integer> pageNumbers, IDocumentReadyListener documentReady); List<PdfDocument> splitByPageNumbers(List<Integer> pageNumbers); void splitByPageCount(int pageCount, IDocumentReadyListener documentReady); List<PdfDocument> splitByPageCount(int pageCount); List<PdfDocument> extractPageRanges(List<PageRange> pageRanges); PdfDocument extractPageRange(PageRange pageRange); PdfDocument getPdfDocument(); List<PdfDocument> splitByOutlines(List<String> outlineTitles);  }
@Test @LogMessages(messages = { @LogMessage(messageTemplate = LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY, count = 2) }) public void splitDocumentTest03() throws IOException, InterruptedException { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); PageRange pageRange1 = new PageRange().addPageSequence(4, 15).addSinglePage(18).addPageSequence(1, 2); PageRange pageRange2 = new PageRange().addSinglePage(99).addSinglePage(98).addPageSequence(70, 99); List<PdfDocument> splitDocuments = new PdfSplitter(inputPdfDoc) { int partNumber = 1; @Override protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { try { return new PdfWriter(destinationFolder + "splitDocument3_" + String.valueOf(partNumber++) + ".pdf"); } catch (FileNotFoundException e) { throw new RuntimeException(); } } }.extractPageRanges(Arrays.asList(pageRange1, pageRange2)); for (PdfDocument pdfDocument : splitDocuments) { pdfDocument.close(); } for (int i = 1; i <= 2; i++) { Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "splitDocument3_" + i + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument3_" + String.valueOf(i) + ".pdf", destinationFolder, "diff_")); } }
@Test @LogMessages(messages = { @LogMessage(messageTemplate = LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY, count = 2) }) public void splitDocumentTest04() throws IOException, InterruptedException { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); PageRange pageRange1 = new PageRange("even & 80-").addPageSequence(4, 15).addSinglePage(18).addPageSequence(1, 2); PageRange pageRange2 = new PageRange("99,98").addPageSequence(70, 99); List<PdfDocument> splitDocuments = new PdfSplitter(inputPdfDoc) { int partNumber = 1; @Override protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { try { return new PdfWriter(destinationFolder + "splitDocument4_" + String.valueOf(partNumber++) + ".pdf"); } catch (FileNotFoundException e) { throw new RuntimeException(); } } }.extractPageRanges(Arrays.asList(pageRange1, pageRange2)); for (PdfDocument pdfDocument : splitDocuments) { pdfDocument.close(); } for (int i = 1; i <= 2; i++) { Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "splitDocument4_" + i + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument4_" + String.valueOf(i) + ".pdf", destinationFolder, "diff_")); } }