Skip to content
ComPDF
Guides

Move Pages

Move a specified page within the document to a target position. The steps to move pages are as follows:

  1. Specify the source page index and target position index.
  2. Call the move page interface.
  3. Refresh the document to apply the changes.

The following example demonstrates how to move pages:

tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);

<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={ComPDFKit.getDefaultConfig({})}
/>

// Move page 1 to the position of page 2 (page indices start from 0)
const fromIndex = 0;
const toIndex = 1;
const moveResult = await pdfReaderRef.current?._pdfDocument.movePage(
  fromIndex,
  toIndex
);
if (moveResult) {
  // Refresh the page to apply the move effect
  await pdfReaderRef.current?.reloadPages2();
}