Merge PDF Pages Using the JavaScript Library
Two or more PDF files can be merged together by using the insertPage function on the Document instance. See the following example:
WebViewer({
... // other options
// when inserting pages from another document, the 'useDownloader' option should be false
url: '/url/to/first.pdf',
useDownloader: false,
}, document.getElementById('viewer'))
.then(async instance => {
const { documentViewer } = instance.Core;
const doc = documentViewer.getDocument();
const secondDoc = await instance.Core.createDocument('url/to/second.pdf');
const pagesToInsert = [4, 5, 6];
const pageIndexToInsert = doc.getPageCount() + 1;
// in this example doc.getPageCount() returns 3
doc.insertPages(secondDoc, pagesToInsert, pageIndexToInsert).then(() => {
doc.getPageCount(); // 6
});
});Merge files without WebViewer
When using Core without WebViewer, certain flags need to set to make Core function correctly and to be able to load web workers from the correct path. You need to set setPDFWorkerPath, forceBackendType and disableEmbeddedJavaScript as shown:
Last updated
Was this helpful?