Skip to content
ComPDF
Guides

替换页面

以下是替换页面的步骤:

  1. 删除目标文件需要被替换的页码。
  2. 将替换页面插入原文档被删除的位置,完成页面的替换。

以下是替换页面的示例代码:

java
// 删除文档的第一页。
document.removePages(new int[]{0});
CPDFDocument document2 = new CPDFDocument(context);
document2.open(pdfPath);
// 将另一份文档的第一页插入原文档的第一页位置,完成替换。
document.importPages(document2, new int[]{0}, 0);
kotlin
// 删除文档的第一页。
document.removePages(new int[]{0})
val document2 = new CPDFDocument(context)
document2.open(pdfPath)
// 将另一份文档的第一页插入原文档的第一页位置,完成替换。
document.importPages(document2, intArrayOf(0), 0)

当文档已绑定并通过 CPDFReaderView 显示时,在对文档页面进行修改后,需要调用以下接口刷新视图,使变更立即生效:

java
cpdfReaderView.reloadPages();