Skip to content
ComPDF
Guides

Delete Pages

Delete specified pages from the current document. The steps to delete pages are as follows:

  1. Specify the collection of page indices to delete.
  2. Call the delete pages interface.
  3. Refresh the document to apply the changes.

The following example demonstrates how to delete pages:

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

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

// Delete pages 1, 2, and 3 (page indices start from 0)
const deleteResult = await pdfReaderRef.current?._pdfDocument.removePages([0, 1, 2]);
if (deleteResult) {
  // Refresh the page to apply the deletion effect
  await pdfReaderRef.current?.reloadPages2();
}