Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 29, 2025 10:19
Show Gist options
  • Save aspose-com-gists/d2cae991216d1abe7bd20c3732af4536 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/d2cae991216d1abe7bd20c3732af4536 to your computer and use it in GitHub Desktop.
Resize PDF Document in Python - Change PDF Page Size in Python
# Step 1: Import the Aspose.PDF module
import aspose.pdf as ap
# Step 2: Load the PDF document
document = ap.Document("input.pdf")
# Step 3: Resize all pages to a predefined size using the PageSize enum
for page in document.pages:
page.resize(ap.PageSize.A3)
# Step 4: Save the updated PDF
document.save("output_a3.pdf")
# Step 1: Import the Aspose.PDF module
import aspose.pdf as ap
# Step 2: Load the input PDF file
document = ap.Document("input.pdf")
# Step 3: Define new page dimensions in points (Letter size = 612 x 792)
new_width = 612
new_height = 792
# Step 4: Loop through all pages and apply the new size
for page in document.pages:
page.set_page_size(new_width, new_height)
# Step 5: Save the resized PDF to disk
document.save("output_custom_size.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment