PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Insert a blank page or pages from other PDFs into the target document.
This example shows how to insert a blank page:
CPDFDocument document = new CPDFDocument(context);
document.open(pdfPath);
// Insert after the first page.
int pageIndex = 1;
float pageWidth = 595F;
float pageHeight = 842F;
document.insertBlankPage(pageIndex, pageWidth, pageHeight);val document = CPDFDocument(context)
document.open(pdfPath)
// Insert after the first page.
val pageIndex = 1
val pageWidth = 595F
val pageHeight = 842F
document.insertBlankPage(pageIndex, pageWidth, pageHeight)This example shows how to insert pages from other PDFs:
CPDFDocument document2 = new CPDFDocument(context);
document2.open(pdfPath);
document.importPages(document2, new int[]{0}, 1);val document2 = CPDFDocument(context)
document2.open(pdfPath)
document.importPages(newDocument, intArrayOf(0), 1)Insert Image Page
The following demonstrates how to insert an image as a PDF page:
CPDFDocument document = new CPDFDocument(context);
document.open(pdfPath);
String imagePath = "xxx.png";
int insertIndex = 0;
CPDFPage insertPage = document.insertPageWithImagePath(insertIndex, imageWidth, imageHeight,
imagePath, PDFDocumentImageMode.PDFDocumentImageModeScaleAspectFit);
if (insertPage != null && insertPage.isValid()) {
// Image page inserted successfully. If the document is displayed via CPDFReaderView, refresh the pages
cpdfReaderView.reloadPages();
}val document = CPDFDocument(context)
document.open(pdfPath)
val imagePath = "xxx.png"
val insertIndex = 0
val insertPage = document.insertPageWithImagePath(
insertIndex,
imageWidth,
imageHeight,
imagePath,
PDFDocumentImageMode.PDFDocumentImageModeScaleAspectFit
)When the document is bound and displayed via CPDFReaderView, after modifying the document pages, you need to call the following method to refresh the view so that changes take effect immediately:
cpdfReaderView.reloadPages();