Forum Discussion
How can I crop PDF pages for free?
PyMuPDF is an option if you’re comfortable with a short Python script and want to specify exactly which pages get cropped. It processes the file locally and doesn’t turn the text and tables into screenshots.
Install it:
python -m pip install pymupdf
This example trims half an inch from each edge, except on pages 3 and 7, where it leaves more horizontal space for wider tables:
import pymupdf
with pymupdf.open("report.pdf") as doc:
for number, page in enumerate(doc, start=1):
box = page.cropbox
side = 12 if number in {3, 7} else 36
top_bottom = 36
if box.width <= 2 * side or box.height <= 2 * top_bottom:
continue
page.set_cropbox(pymupdf.Rect(
box.x0 + side,
box.y0 + top_bottom,
box.x1 - side,
box.y1 - top_bottom,
))
doc.save("cropped.pdf")
Save this as crop.py beside your PDF, then run python crop.py. Measurements are in points: 72 points = one inch.
The page numbers and margins are examples, not automatic content detection. Start with a copy and adjust them to your report. PyMuPDF is available under AGPL or a commercial licence, which matters if you plan to incorporate it into software.