Rotating a PDF page using JavaScript

To rotate a page in a PDF document.

JavaScript

1async function main() {
2 const doc = await PDFNet.PDFDoc.createFromURL(filename);
3
4 // Rotate the first page 90 degrees clockwise.
5 const page = await doc.getPage(1);
6 const originalRotation = await page.getRotation();
7 var rotation;
8 switch (originalRotation)
9 {
10 case Page.e_0: rotation = Page.e_90; break;
11 case Page.e_90: rotation = Page.e_180; break;
12 case Page.e_180: rotation = Page.e_270; break;
13 case Page.e_270: rotation = Page.e_0; break;
14 default: rotation = Page.e_0; break;
15 }
16 page.setRotation(rotation);
17}
18PDFNet.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.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales