PdfSplitter { public void splitByPageCount(int pageCount, IDocumentReadyListener documentReady) { for (int startPage = 1; startPage <= pdfDocument.getNumberOfPages(); startPage += pageCount) { int endPage = Math.min(startPage + pageCount - 1, pdfDocument.getNumberOfPages()); PageRange currentPageRange = new PageRange().addPageSequence(startPage, endPage); PdfDocument currentDocument = createPdfDocument(currentPageRange); pdfDocument.copyPagesTo(startPage, endPage, currentDocument); documentReady.documentReady(currentDocument, currentPageRange); } } 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 splitDocumentTest02() throws IOException, InterruptedException { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); new PdfSplitter(inputPdfDoc) { int partNumber = 1; @Override protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { try { return new PdfWriter(destinationFolder + "splitDocument2_" + String.valueOf(partNumber++) + ".pdf"); } catch (FileNotFoundException e) { throw new RuntimeException(); } } }.splitByPageCount(60, new PdfSplitter.IDocumentReadyListener() { @Override public void documentReady(PdfDocument pdfDocument, PageRange pageRange) { if (new PageRange("61-120").equals(pageRange)) { pdfDocument.getDocumentInfo().setAuthor("Modified Author"); } pdfDocument.close(); } }); for (int i = 1; i <= 3; i++) { Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "splitDocument2_" + String.valueOf(i) + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument2_" + String.valueOf(i) + ".pdf", destinationFolder, "diff_")); } }