Rotate a PDF page in Java

This article demonstrates how to rotate a PDF page using Spire.PDF for Java.

Below is the screenshot of the input.pdf file:

Rotate a PDF page in Java

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.PdfPageRotateAngle;

import java.io.IOException;

public class RotatePDFPage {
    public static void main(String[] args) throws IOException {
        //Load the PDF document
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("Input.pdf");

        //Get the first page
        PdfPageBase page = pdf.getPages().get(0);

        //Get the original rotation angle of the page
        int rotateAngle = page.getRotation().getValue();

        //Rotate the PDF page 90 degrees clockwise based on the original rotation angle
        rotateAngle += PdfPageRotateAngle.Rotate_Angle_90.getValue();
        page.setRotation((PdfPageRotateAngle.fromValue(rotateAngle)));

        //Save the PDF document
        pdf.saveToFile("Rotated.pdf");
    }
}

Output:

Rotate a PDF page in Java