3

I am using Apache PDFBox to handle PDF files in my Java application. I would like to split a PDF document, for example, on every page.

Is it possible to do this wirth Apache PDFBox? If so, how?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Shaheedul Islam
  • 125
  • 1
  • 1
  • 13
  • 1
    For some advanced splitting, see here: https://stackoverflow.com/questions/32002830/how-to-split-pdf-file-by-result-in-java-pdfbox Btw in the future, consider a google search before asking a one-line question. Searching for "pdfbox split" in google finds just the class from the answer by Tunaki. – Tilman Hausherr Aug 27 '15 at 22:07
  • I still need an example. – danny117 Jan 25 '17 at 15:05

1 Answers1

7

This is possible using a Splitter.

This is a sample code that will split a document on every page:

PDDocument document = PDDocument.load(myPDF);
Splitter splitter = new Splitter();
List<PDDocument> splittedDocuments = splitter.split(document);

You can control the number of pages on every splitted PDF using setSplitAtPage(split).

Tunaki
  • 132,869
  • 46
  • 340
  • 423