Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Insert Pages

Insert a blank page or pages from other PDFs into the target document.

Insert Blank Pages

This example shows how to insert a blank page:

java
CPDFDocument document = new CPDFDocument();
document.open(pdfPath);
int pageIndex = 1; // Insert after the first page.
float pageWidth = 595F;
float pageHeight = 842F;
document.insertBlankPage(pageIndex, pageWidth, pageHeight);

Insert Pages from other PDFs

This example shows how to insert pages from other PDFs:

java
CPDFDocument document2 = new CPDFDocument();
document2.open(pdfPath);
document.importPages(document2, new int[]{0}, 1);