Skip to content
ComPDF
Guides

移动页面

交换文档中两个页面的位置,以下是交换页面的步骤:

  1. 指定要交换的两个页码

  2. 调用交换页面接口

使用 CPDFReaderWidget

dart
CPDFReaderWidgetController? _controller;
// 初始化 CPDFReaderWidget,并在 onCreated 回调中获取 controller
CPDFReaderWidget(
  document: documentPath,
  configuration: CPDFConfiguration(),
  onCreated: (controller) {
    setState(() {
      this._controller = controller;
    });
  },
);

bool result = await document.movePage(fromIndex: 0, toIndex: 1);
if(result){
  controller.reloadPages2();
}

使用 CPDFDocument

dart
// 创建并打开文档
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
  bool result = await document.movePage(fromIndex: 0, toIndex: 1);
}