How to split up the pages from a PDF file in multiple files

0
Hi, I have a PDF document with multiple pages. Now I want to split up the pages in multiple files. How can I do this? I have tried IText but can't seem to get it working. Hope you can help me out!
asked
4 answers
2

Marco,

With appache pdfbox you can split the document into pages as below:

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)

answered
1

That is more a stackoverflow question: https://stackoverflow.com/questions/5736675/itext-split-a-pdf-into-several-pdf-1-per-page

Regards,

Ronald

 

answered
0

Based on the answer from Ronald I have created the following code which is giving me the first page of a PDF.

InputStream is = Core.getFileDocumentContent(this.getContext(), __PDFDocument);
        PdfReader reader = new PdfReader(is);
        
        Document document = new Document(reader.getPageSizeWithRotation(1));
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("hhmmssSSS");
        Random rand = new Random();
        formatter.format(date);
        File file = new File(Core.getConfiguration().getTempPath().toString() + "/" + formatter.format(date) + rand.nextInt(50) + ".pdf");
        
        PdfCopy writer = new PdfCopy(document, new FileOutputStream(file));
        document.open();
        PdfImportedPage page = writer.getImportedPage(reader, 1);
        writer.addPage(page);
        document.close();
        writer.close();
        InputStream IsFile = new FileInputStream(file);
        
        IMendixObject obj = Core.instantiate(this.getContext(), CertificateDocument.getType());
        
        Core.storeFileDocumentContent(this.getContext(), obj, IsFile);
        
        is.close();
        IsFile.close();
        file.delete();
        
        return obj;

answered
0

I used Split PDF Software It runs on all Windows versions without any problem. I have separated several pages from a PDF of 250 pages in few minutes using this software.

Visit at more info; https://www.osttopstapp.com/pdf-split.html

answered