PDFBox: Split document into multiple pages


/ Published in: Java
Save to your folder(s)

Opens an existing document and splits it into multiple documents, one for each page.


Copy this code and paste it in your HTML
  1. /**
  2.  * @param args the command line arguments
  3.  * @throws java.io.IOException
  4.  */
  5. public static void main(String[] args) throws IOException {
  6. File file = new File("");
  7. PDDocument document = PDDocument.load(file);
  8.  
  9. Splitter splitter = new Splitter();
  10.  
  11. List<PDDocument> Pages = splitter.split(document);
  12.  
  13. Iterator<PDDocument> iterator = Pages.listIterator();
  14.  
  15. for(int i = 1;iterator.hasNext();i++)
  16. {
  17. PDDocument pd = iterator.next();
  18. pd.save("" + i + ".pdf");
  19. }
  20.  
  21. document.close();
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.