Skip to content
ComPDF
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Replace Pages

The steps to replace pages are as follows:

  1. Remove the pages in the target file that need to be replaced.
  2. Insert the replacement pages into the location where the original document was deleted.

This example shows how to replace pages:

javascript
// Remove the first page from the document.
docViewer.removePages([0]);

// Insert the first page of another document into the original document's first-page position to complete the replacement.
const file = {...}; // File Object.
const pageIndexToInsert = 0;
const pagesToInsert = 'all'; // Insert the range of PDF pages.

docViewer.insertPages(file, pageIndexToInsert, pagesToInsert);