Guides
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(context);
document.open(pdfPath);
// Insert after the first page.
int pageIndex = 1;
float pageWidth = 595F;
float pageHeight = 842F;
document.insertBlankPage(pageIndex, pageWidth, pageHeight);kotlin
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)Insert Pages from other PDFs
This example shows how to insert pages from other PDFs:
java
CPDFDocument document2 = new CPDFDocument(context);
document2.open(pdfPath);
document.importPages(document2, new int[]{0}, 1);kotlin
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:
java
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();
}kotlin
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:
java
cpdfReaderView.reloadPages();