Resize PDF via Python

Change PDF Page Size. Use Aspose.PDF for Python for .NET to modify PDF documents programmatically

Resize PDF Pages with Python

Do you need to resize PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With Python libraries like Aspose.PDF – are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional Python developers.

This Python library enables developers to resize PDF documents quickly and efficiently through programming. This library shows you how easily to update or change the page dimensions in an existing PDF file programmatically with Python. It is a standalone solution for processing PDF documents in Python that does not require the installation of any third-party software.

In order to resize PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy-to-use document manipulation API for Python via .NET platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

How to Resize PDF documents


You need Aspose.PDF for Python to try the code in your environment.

  1. Load the source PDF file.
  2. Get the pages into the PageCollection object.
  3. Get a given page.
  4. Call the SetPageSize(..) method to update its dimensions.
  5. Call the Document class Save(..) method to generate the PDF file with updated page dimensions.

If you want to resize PDF files for your tasks, this solution can help. With this powerful Aspose.PDF Python for .NET library, you can update or change the page dimensions (size) of an existing files. This professional tool uses Python to resize PDF effectively. The following example demonstrates how to change size of PDF document in Python:

Resize PDF - Python

This sample code shows how to Resize PDF Pages - Python


    document = ap.Document(input_pdf)

    # Get particular page
    page = document.pages[1]

    # Set the page size as A4 (11.7 x 8.3 in) and in Aspose.Pdf, 1 inch = 72 points
    # So A4 dimensions in points will be (842.4, 597.6)
    page.set_page_size(597.6, 842.4)

    # Save the updated document
    document.save(output_pdf)

About Aspose.PDF for Python API

Aspose.PDF for Python via .NET API supports most established PDF standards and PDF specifications. It allows developers to insert tables, graphs, images, hyperlinks, custom fonts - and more - into PDF documents. Moreover, it is also possible to resize PDF documents. Aspose.PDF for Python via .NET provides excellent security features to develop secure PDF documents. Some of the key features of Aspose.PDF for Python via .NET API include:

  • Ability to read & export PDF in multiple image formats including BMP, GIF, JPEG & PNG.
  • Set basic information (e.g. author, creator) of the PDF document.
  • Conversion Features: Convert PDF to Word, Excel, and PowerPoint. Convert PDF to Images formats. Convert PDF file to HTML format and vice versa. Convert PDF to EPUB, Text, XPS, etc.

You can find more information about Aspose.PDF for Python via .NET API on our documentation on how to use API.