Rotate PDF pages

Rotate PDF pages with an easy-to-use REST API.

Basic page rotation

The PDF page rotation tool can be used in a pipeline via a rotate-pages task.

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

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

      form.append(
        'tasks',
        [
          {
            tool: 'rotate-pages',
            // Set first page rotation to 90 degrees
            options: { pages: [{ page: 0, rotation: 90 }] },
          },
        ],
      );
    
  

You can specify a rotation of one of the following values:

  • 0
  • 90
  • 180
  • 270

Range page rotation

You can rotate multiple pages in a single statement by specifying a range rather than a list of indexes.

    
      // The rotation of all pages to 90 degrees
      options: { pages: [{ range: [0, 'last'], rotation: 90 }] }
    
  

Target pages with a certain orientation

The rotation tool allows you to target pages that currently have a certain orientation, allowing you to target them without knowing their indexes.

    
      // Update the rotation of all the upside down pages to put them right side up
      options: { pages: [{ current: 180, rotation: 0 }] }
    
  

Multiple rotation instructions

You can define several rotation instructions.

The instructions are executed in the order given in the pages parameter. That means that if you give multiple rotation instructions, rotation instructions based on the current pages rotation may depand on the previous instructions.

    
      options: {
        pages: [
          // Reversing page rotation...
          // Change the rotation of pages right side up to put them upside down
          { current: 0, rotation: 180 },
          // Change the rotation of pages upside down to put them right side up
          { current: 180, rotation: 0 },
        ],
      },