PDF pages can be rotated 0, 90, 180, or 270 degrees. To rotate pages with the user interface (UI), simply open the pages panel, select a page or a group of pages, right-click and select Rotate pages. You can also press Ctrl + Shift + R on the keyboard to open the page rotation UI.
When a page is not rotated (0 degrees), and it gets rotated clockwise by 90 degrees, the page rotation is 90 degrees, continuing clockwise by 90-degree increments produces rotations of 180, 270, and back to 0. You can also change page rotations with a script. The document setPageRotations( ) method takes four input parameters:
nStart - The zero-based start page of the range of pages to rotate.
nEnd - The zero-based end page of the range of pages to rotate.
nRotate - The degrees of rotation (0, 90, 180, 270).
/*The following script sets the page rotation of pages 1 through 10 to 90° */
this.setPageRotations(0, 9, 90);
Is The Page Rotated?
A page might appear as “landscape” view, but depending on how it was produced, it could have any page rotation. It could be a portrait 8.5" x 11" page rotated 90 degrees. It could also be an 11" x 8.5" page with a degree rotation of zero. I have even seen pages with 180° rotation (upside down) that look right-side up because of the way they were fed through a scanner, coming out upside-down with zero rotation, then rotated to right-side up with 180° rotation.
Try This Example
Open a new document in Microsoft Word and set the layout to Landscape.
Type some text and save the document.
Three Ways To Convert It To PDF
There are at least three ways to convert this 1-page Word document to PDF when you have Adobe Acrobat on your computer. Let’s look at three of them and then test the page rotation of the PDFs by running the following script in the console:
this.getPageRotation(0);
Use the Acrobat plug-in menu in Word and select Create PDF.
Select File > Print, then select Adobe PDF as the printer.
Close the file, right-click it and select Convert to Adobe PDF
All three methods produce landscape view documents. Bullet points one and three produce 0° page rotation. Depending on the PDF printer settings, point two can produce a 90° page rotation.
User Space: Default vs Rotated
The rect property of a form field is in rotated user space. In other words, the crop box changes as the page is rotated. It’s the rotated view on the page that matters, not when pages with rotations other than zero are rotated back to zero. The left side of the page as viewed on the screen is always zero in the crop box, as is the bottom of the page. The top is the height and the right side is the width:
//8.5" x 11" page with zero rotation
this.getPageBox("Crop",this.pageNum)//returns:
[0,792,612,0]
//Same page that has been rotated 90 degrees
this.getPageBox("Crop", this.pageNum)//returns:
[0,612,792,0]
//Same page that has been rotated 180 degrees
this.getPageBox("Crop", this.pageNum)//returns:
[0,792,612,0]
//Same page that has been rotated 270 degrees
this.getPageBox("Crop", this.pageNum)//returns:
[0,612,792,0]
Notice 0 and 180 have the same crop box (page coordinates), as do 90 and 270?
Positioning form fields programmatically relative to the crop box is the same script for every rotation because the crop box changes (rotated user space). This is not the case for stamps and other annotations because the rect property is in default user space. The rect property is relative to crop box of the page when the page is rotated back to zero.
Try This
For reference, read Positioning PDF Stamps Programmatically Part II. With a regular PDF page with zero rotation, place the Reviewed Stamp in top left corner of the page:
//Define the crop box
var cb=this.getPageBox("Crop", this.pageNum);
//Place Reviewed stamp in top left corner
this.addAnnot({
type:"Stamp",
AP:"#DReviewed",
page:this.pageNum,
rect:[0,cb[1]-55.11,255.64,cb[1]]
});
Now rotate the page clockwise in 90 degree increments:
The image above shows the position of the stamp on the page as viewed on the screen for each page rotation. The stamps also have a rotation property. If you selected the stamp at each stage of rotation and run the following script in the console it will return the stamps rotation:
this.selectedAnnots[0].rotate;
How To Adjust For The Rotation
Stay tuned…