Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

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
const doc = documentViewer.getDocument();

// Remove the first page from the document.
await doc.removePages([1]);

// Insert the first page of another document into the original document's first-page position to complete the replacement.
const file = {...}; // File Object.
const insertBeforeThisPage = 1;
const sourceDocument = await instance.Core.createDocument(file);

// Insert all pages of the PDF when the page numbers are omitted.
await doc.insertPages(sourceDocument, undefined, insertBeforeThisPage);