For the complete documentation index, see llms.txt. This page is also available as Markdown.

Merge PDF Pages Using the JavaScript Library

Requirements

These packages are required to use these features in production. Trial keys have unlimited access to all features

Package: Page ManipulationLive demo

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?