PdfSplitter { public void splitByPageNumbers(List<Integer> pageNumbers, IDocumentReadyListener documentReady) { int currentPageNumber = 1; for (int ind = 0; ind <= pageNumbers.size(); ind++) { int nextPageNumber = ind == pageNumbers.size() ? pdfDocument.getNumberOfPages() + 1 : (int) pageNumbers.get(ind); if (ind == 0 && nextPageNumber == 1) continue; PageRange currentPageRange = new PageRange().addPageSequence(currentPageNumber, nextPageNumber - 1); PdfDocument currentDocument = createPdfDocument(currentPageRange); pdfDocument.copyPagesTo(currentPageNumber, nextPageNumber - 1, currentDocument); documentReady.documentReady(currentDocument, currentPageRange); currentPageNumber = nextPageNumber; } } 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 = 3) }) public void splitDocumentTest01() throws IOException, InterruptedException { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); List<Integer> pageNumbers = Arrays.asList(30, 100); List<PdfDocument> splitDocuments = new PdfSplitter(inputPdfDoc) { int partNumber = 1; @Override protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { try { return new PdfWriter(destinationFolder + "splitDocument1_" + String.valueOf(partNumber++) + ".pdf"); } catch (FileNotFoundException e) { throw new RuntimeException(); } } }.splitByPageNumbers(pageNumbers); for (PdfDocument doc : splitDocuments) doc.close(); for (int i = 1; i <= 3; i++) { Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "splitDocument1_" + String.valueOf(i) + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument1_" + String.valueOf(i) + ".pdf", destinationFolder, "diff_")); } }