PdfSplitter { public List<PdfDocument> splitBySize(long size) { List<PageRange> splitRanges = new ArrayList<>(); int currentPage = 1; int numOfPages = pdfDocument.getNumberOfPages(); while (currentPage <= numOfPages) { PageRange nextRange = getNextRange(currentPage, numOfPages, size); splitRanges.add(nextRange); List<Integer> allPages = nextRange.getQualifyingPageNums(numOfPages); currentPage = (int) allPages.get(allPages.size() - 1) + 1; } return extractPageRanges(splitRanges); } 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 public void splitDocumentBySize() throws IOException, InterruptedException { String inputFileName = sourceFolder + "splitBySize.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); PdfSplitter splitter = new PdfSplitter(inputPdfDoc) { int partNumber = 1; @Override protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { try { return new PdfWriter(destinationFolder + "splitBySize_part" + String.valueOf(partNumber++) + ".pdf"); } catch (FileNotFoundException e) { throw new RuntimeException(); } } }; List<PdfDocument> documents = splitter.splitBySize(100000); for (PdfDocument doc : documents) { doc.close(); } for (int i = 1; i <= 4; ++i) { Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "splitBySize_part" + i + ".pdf", sourceFolder + "cmp/" + "cmp_splitBySize_part" + i + ".pdf", destinationFolder, "diff_")); } }