Skip to content
ComPDF
Guides

Move Pages

Swap the positions of two pages in the document. Here are the steps:

  1. Specify the two page numbers to swap
  2. Call the swap pages interface

Using CPDFReaderWidget:

dart
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and get controller in onCreated callback
CPDFReaderWidget(
  document: documentPath,
  configuration: CPDFConfiguration(),
  onCreated: (controller) {
    setState(() {
      this._controller = controller;
    });
  },
);

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

Using CPDFDocument:

dart
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
  bool result = await document.movePage(fromIndex: 0, toIndex: 1);
}