Some test text!

Search
Hamburger Icon

Web / Guides

Rotating a PDF page using JavaScript

Make sure you have Full API enabled in WebViewer.

To rotate a page in a PDF document.

async function main() {
  const doc = await PDFNet.PDFDoc.createFromURL(filename);

  // Rotate the first page 90 degrees clockwise.
  const page = await doc.getPage(1);
  const originalRotation = await page.getRotation();
  var rotation;
  switch (originalRotation)
  {
    case Page.e_0:   rotation = Page.e_90;  break;
    case Page.e_90:  rotation = Page.e_180; break;
    case Page.e_180: rotation = Page.e_270; break;
    case Page.e_270: rotation = Page.e_0;   break;
    default:         rotation = Page.e_0;   break;
  }
  page.setRotation(rotation);
}
PDFNet.runWithCleanup(main);

About rotating pages

A page can be rotated clockwise, by 90 degrees, when displayed or printed. The Page.GetRotation() method returns the Page.Rotate enum specifying the current rotation. Similarly, Page.SetRotation() sets the current rotation.

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales