Learn how to Resize PDF Document or Change PDF Page Size in Python
Last active
May 29, 2025 10:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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