Rotating PDF Pages Using JavaScript

The rotatePages operation will rotate the specified pages by the desired amount; only multiples of 90 under 360 are allowed as values.

If the page is already rotated, this will add the specified rotation, so if a page is already rotated 90 degrees and you apply a 90-degreee rotation, it’ll result in the page being rotated 180 degrees:

instance.applyOperations([
  {
    type: "rotatePages",
    pageIndexes: [0], // Rotate page 0.
    rotateBy: 90 // Rotate page 90 degrees clockwise.
  }
]);

After this operation is complete, call exportPDF to get a buffer containing the data for the final PDF.

If you need to apply this operation and export in one step, you can provide the same argument you provide to applyOperations to exportPDFWithOperations to get a buffer containing the data for the final PDF.