
When working with PDF files, you often need to trim page size programmatically, such as removing white margins. This article shows how to crop PDF pages in Python with step‑by‑step guidance and a code sample.
Python Library to Crop PDF Pages
To crop PDF files, we will use Aspose.PDF for Python. The library provides a full set of features to create and manipulate PDFs from Python applications. Install it from PyPI with:
pip install aspose-pdf
Crop a PDF Page in Python
Below are the steps to crop pages in a PDF using our Python PDF library. The example crops only the first page, but you can adjust the code to target any pages.
- Load the PDF with the Document class.
- Create a Rectangle that defines the crop area.
- Access Document.pages, select the page, and assign the Rectangle to crop_box, trim_box, art_box, and bleed_box.
- Save the updated PDF with Document.save().
The code sample demonstrates how to crop a PDF page in Python.
Online Tool to Crop PDF Files
We also offer a free online tool to crop PDF files that works in a few clicks. Use it to test PDF cropping without signing up.

Get a Free License
You can obtain a free temporary license to evaluate the PDF cropping feature without limitations.
Explore Python PDF Library
Visit the documentation of our Python PDF library to discover its capabilities. For suggestions or questions, join our forum.
Conclusion
You have learned how to crop PDF pages in Python. Using the steps and code above, you can add PDF cropping to your application. Install Aspose.PDF for Python and leverage its powerful PDF manipulation features.