Order PDF pages

Learn how to use the PDF page move tool to reorder your PDFs.

Basic page moving

The PDF reordering tool can be used in a pipeline via a order-pages task.

The options parameter allows you to specify which pages you want to move, based on their indexes.

    
      // Creating the form data for the pipeline
      const form = new FormData();

      form.append(
        'tasks',
        [
          {
            tool: 'order-pages',
            // Shifting the first page by 2 positions downward
            options: { pages: [{ page: 0, shift: 2 }] },
          },
        ],
      );
    
  

The shift parameter allows you to specify:

  • an offset towards the end of the file if its value is positive
  • an offset towards the start of the file if its value is negative

Moving a page range

If you want to move several successive pages at once, you can use a range instruction rather than giving a list of indexes.

    
      // Shifting the first 3 pages by 1 position downward
      options: { pages: [{ range: [0, 2], shift: 1 }] }
    
  

Moving pages to a specific position

In addition to being able to use a shift, you can also use a target position to move pages.

    
      // Moving the last page to the first position
      options: { pages: [{ page: 'last', position: 0 }] }
    
  

When using a range instruction, the given position indicates the position of the first page. The next pages in the range will be moved following.

    
      // Moving the last 3 pages to the start of the document
      options: { pages: [{ range: ['last-3', 'last'], position: 0 }] }
    
  

Multiple ordering instructions

You can define several PDF pages ordering instructions.

The instructions are executed in the order given in the pages parameter. It is therefore important to know that for instruction n, the indices must be calculated taking into account instruction n-1.

    
      options: {
        pages: [
          // Moving the first page to the end of the document
          { page: 0, position: 'last' },
          // Moving the second, third and forth pages to the start of the document
          { range: [1, 3], shift: -1 },
        ],
      },