Forum Discussion
How can I crop PDF pages for free?
To crop PDF pages selectively while leaving the others untouched, the free Python library pypdf can do it with a small script. It’s more useful for repeatable cropping than for visually deciding where the edges should go.
Install the library:
python -m pip install pypdf
Save this as crop_selected.py:
from pypdf import PdfWriter
writer = PdfWriter(clone_from="report.pdf")
# Printed page positions, starting at 1.
pages_to_crop = {1, 2, 4, 5, 6}
margin = 24 # Points: 72 points = one inch.
for number, page in enumerate(writer.pages, start=1):
if number not in pages_to_crop:
continue
box = page.cropbox
left, bottom = float(box.left), float(box.bottom)
right, top = float(box.right), float(box.top)
if right - left > 2 * margin and top - bottom > 2 * margin:
box.lower_left = (left + margin, bottom + margin)
box.upper_right = (right - margin, top - margin)
with open("cropped.pdf", "wb") as output:
writer.write(output)
Put it beside report.pdf and run:
python crop_selected.py
In this example, pages 3 and 7—and any other unlisted pages—stay unchanged, which gives you a way to protect the wider tables. Change the page list and margin to suit your document.
This changes the visible page boundaries rather than deleting the hidden content. It won’t automatically find white borders or significantly reduce the PDF’s file size.