Rotate PDF Pages in Python

This topic describes how to update or change the page orientation of pages in an existing PDF file programmatically with Python.

Use this page when you need to switch pages between portrait and landscape orientation or apply rotation angles to existing PDF content.

Change Page Orientation

This function rotates every page of a PDF Document 90 degrees clockwise using Aspose.PDF for Python. It is useful for correcting page orientation issues, such as scanned documents that are sideways. The original PDF remains unchanged, and the rotated version is saved as a new file.

import sys
import aspose.pdf as ap
from os import path

def rotate_page(infile, outfile):
    document = ap.Document(infile)
    for page in document.pages:
        page.rotate = ap.Rotation.ON90

    document.save(outfile)