Closed
PDF file needs to be split into multiple PDF files
- PDF file needs to be split into multiple PDF files, such that one file has details of only one applicant. Later each file needs to be tagged for the respective applicant’s case?
@DolluM39Hi just simple create function for do it. below is sample code.
1. Download the pdfbox jar and import on Pega.
2. Create function and using method from pdf box
import java.io.File; import java.io.IOException; import java.util.List; import java.util.Iterator; public class SplittingPDF { public static void main(String[] args) throws IOException { //Loading an existing PDF document File file = new File("C:/pdfBox/splitpdf_IP.pdf"); PDDocument doc = PDDocument.load(file); //Instantiating Splitter class Splitter splitter = new Splitter(); //splitting the pages of a PDF document List<PDDocument> Pages = splitter.split(doc); //Creating an iterator Iterator<PDDocument> iterator = Pages.listIterator(); //Saving each page as an individual document int i = 1; while(iterator.hasNext()){ PDDocument pd = iterator.next(); pd.save("C:/pdfBox/splitOP"+ i++ +".pdf"); } System.out.println("PDF splitted"); } }