Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Changing a PDF’s margins can mean cropping what readers see, adding blank page area around existing content, or moving or scaling that content. These operations are not interchangeable: a crop changes the visible boundary, while genuine extra whitespace requires a larger page canvas and deliberate content placement.
Choose the margin change you actually need
- Hide edge material: adjust the visible page boundary with a CropBox. The cropped content may remain in the file.
- Add white space around the page content: create a larger destination page and place the existing content within it. Changing the CropBox alone does not add page area.
- Change the content’s size or position: apply a transformation, then ensure the page boxes and content placement match the intended result.
PDF page boxes describe page geometry. The MediaBox defines the physical page dimensions; the CropBox defines the visible region. PyMuPDF documents these page-box operations and their constraints in its Page documentation. The pypdf guide to cropping and transforming PDFs likewise distinguishes changing the view from transforming content or changing the page canvas.
Crop visible margins with PyMuPDF
Use PyMuPDF’s Page.set_cropbox() when the goal is to show a smaller rectangular portion of a page. The rectangle must be finite, non-empty, and contained within the page’s MediaBox, according to the PyMuPDF Page documentation.
For example, this pattern crops a page to a rectangle measured from the unrotated page coordinate space:
#1 Best Overall
import pymupdf
source = "input.pdf"
destination = "cropped.pdf"
with pymupdf.open(source) as doc:
page = doc[0]
# Replace these values with a valid rectangle inside the MediaBox.
page.set_cropbox(pymupdf.Rect(36, 36, 576, 756))
doc.save(destination)
Those coordinates are only an example, not a universal margin setting. Inspect the page dimensions and existing boxes before choosing a rectangle. Cropping changes what is visible; it does not necessarily erase content outside the CropBox. pypdf’s documentation explains that material outside the viewbox can remain in the PDF and may be restored by changing the box.
Add actual whitespace around existing content
To add white space, the page canvas and the content placement must be handled together. Create or use a destination page with larger dimensions, then merge or place the original page content onto it with a translation that leaves the desired space around the content. If the content should also change size, scale it separately; scaling a page and scaling its contents are distinct operations in the pypdf transformation guide.
Conceptually, for a page of width W and height H, adding margins left, right, top, and bottom calls for a destination canvas of width W + left + right and height H + top + bottom. The original content then needs to be translated by the left and bottom offsets in the destination coordinate system. Verify the library’s coordinate conventions and the resulting page boxes rather than assuming that changing one box will reposition the content correctly.
pypdf documents page-box adjustments, transformations, and merging transformed pages; it also notes that placing margins around merged pages requires additional work. PyMuPDF documents that changing a non-empty page’s MediaBox can move content or make it disappear, because content placement depends on page dimensions. Avoid treating a MediaBox edit as a safe shortcut for adding margins.
Account for units, page size, and rotation
PDF coordinates are expressed in points, with 72 points per inch. More importantly, a page’s reported rectangle and the coordinates used for operations may not describe a rotated page in the same way. PyMuPDF states that page-operation coordinates are relative to the unrotated page: rotation affects Page.rect, while Page.cropbox does not rotate to match it. See the project’s The Basics and Page documentation.
Before applying one set of coordinates to a whole document, inspect each page’s dimensions, rotation, and box values. A document may contain mixed page sizes or orientations, so coordinates that work on one page may crop the wrong area or place content incorrectly on another.
Rank #4
Save safely and verify the result
- Keep the original PDF unchanged and save to a new output path.
- Check representative pages, including pages with different sizes or rotations.
- Confirm that the visible content, whitespace, and page dimensions match the intended result.
- If the goal was to remove sensitive content rather than hide it, do not rely on cropping alone; off-view content may remain in the file.
Neither the cited PyMuPDF nor pypdf documentation establishes comparative performance results. Choose between them based on the operation you need—crop, resize the canvas, or transform content—and verify the saved PDF’s appearance and page geometry.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

