Inserting a page into a PDF using JavaScript
Pages can be inserted into the current PDF document using the insertBlankPages and insertPages functions. Inserting blank pages is fairly straight forward.
Insert blank pages
// config.js
const docViewer = instance.Core.documentViewer;
docViewer.addEventListener('documentLoaded', async () => {
const doc = docViewer.getDocument();
const width = 612;
const height = 792;
docViewer.getPageCount(); // 3
// Insert blank pages
await doc.insertBlankPages([2, 3], width, height);
// The document now contains [page1, newBlankPage1, page2, newBlankPage2, page3]
docViewer.getPageCount(); // 5
});// config.js
const docViewer = instance.Core.documentViewer;
docViewer.addEventListener('documentLoaded', async () => {
const doc = docViewer.getDocument();
const width = 612;
const height = 792;
docViewer.getPageCount(); // 3
// Insert blank pages
await doc.insertBlankPages([2, 3], width, height);
// The document now contains [page1, newBlankPage1, page2, newBlankPage2, page3]
docViewer.getPageCount(); // 5
});Insert a page from another document or the same document
More likely someone will want to insert pages from one PDF into another. To achieve this, instantiate a new Document object by passing the URL of the second PDF to createDocument function as a first parameter.
Last updated
Was this helpful?