Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active August 7, 2025 04:53
Show Gist options
  • Save aspose-com-gists/8580292dc563db644380893602bf31be to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8580292dc563db644380893602bf31be to your computer and use it in GitHub Desktop.
Shrink PDF Size – Try Online & Build with C#, Java, Python
// Step 1: Import Aspose.PDF
using Aspose.Pdf;
// Step 2: Load the PDF document
Document document = new Document("input.pdf");
// Step 3: Resize pages to A3 using PageSize enum
foreach (Page page in document.Pages)
{
page.Resize(PageSize.A3);
}
// Step 4: Save the output
document.Save("output_a3.pdf");
// Load the PDF document
Document pdfDocument = new Document("sample_pdf.pdf");
// Resize all pages to A4
for (Page page : pdfDocument.getPages()) {
page.resize(PageSize.getA4());
}
// Save the modified document
pdfDocument.save("output_a4.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