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

Reordering PDF pages using JavaScript

Requirements

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

Package: Page ManipulationLive demo

Pages in the PDF document can be reordered using the movePages function.

WebViewer(...)
  .then(instance => {
    const { documentViewer } = instance.Core;

    documentViewer.addEventListener('documentLoaded', async () => {
      const doc = documentViewer.getDocument();
      const page1 = 1, page2 = 2, page3 = 3;

      const pagesToMove = [page2, page3];
      const insertBefore = page1;

      await doc.movePages(pagesToMove, insertBefore);
      // pages are now in the order of [page2, page3, page1];
    });
  });
WebViewer(...)
  .then(instance => {
    const { docViewer } = instance;

    docViewer.on('documentLoaded', async () => {
      const doc = docViewer.getDocument();
      const page1 = 1, page2 = 2, page3 = 3;

      const pagesToMove = [page2, page3];
      const insertBefore = page1;

      await doc.movePages(pagesToMove, insertBefore);
      // pages are now in the order of [page2, page3, page1];
    });
  });

Last updated

Was this helpful?