Hi,
Thanks for your inquiry.
Do you want to merge selected pages from one PDF file or merge selected pages form multiple PDF files into one?
For case one, please refer to the code below.
- Code: Select all
//merge selected pages from one PDF file
PdfDocument doc=new PdfDocument();
doc.loadFromFile("……\\……\\……\\filename.pdf");
PdfDocument doc1 = new PdfDocument();
doc1.insertPage(doc,0);
doc1.insertPage(doc,1);
doc1.saveToFile("output.pdf");
For case two, here is the code for your reference.
- Code: Select all
//Merge selected pages from multiple PDF files into one
String[] files = new String[]
{
"……\\……\\……\\filename1.pdf",
"……\\……\\……\\filename2.pdf",
"……\\……\\……\\filename3.pdf",
};
PdfDocument[] docs = new PdfDocument[files.length];
for (int i = 0; i < files.length; i++)
{
docs[i] = new PdfDocument(files[i]);
}
PdfDocument doc = new PdfDocument();
doc.insertPage(docs[0],0);
doc.insertPage(docs[1],1);
doc.insertPage(docs[2],3);
doc.saveToFile("output.pdf");
doc.close();
If my code couldn’t solve your issue, please offer us your input PDF files and describe your requirement in detail.
Best wishes,
Amber
E-iceblue support team