Skip to content

Instantly share code, notes, and snippets.

@edykim
Created July 13, 2025 19:15
Show Gist options
  • Select an option

  • Save edykim/8dbeb90e929b698df1314e95a06c1dba to your computer and use it in GitHub Desktop.

Select an option

Save edykim/8dbeb90e929b698df1314e95a06c1dba to your computer and use it in GitHub Desktop.
crop pdf
# pip3 install pymupdf
import fitz # PyMuPDF
import sys
input_path = sys.argv[1]
output_path = sys.argv[2]
TARGET_RATIO = 1488 / 2266 # ≈ 0.6569 (portrait iPad Mini 7)
doc = fitz.open(input_path)
for page in doc:
rect = page.rect
height = rect.height
target_width = height * TARGET_RATIO
crop_left = (rect.width - target_width) / 2
new_rect = fitz.Rect(crop_left, 0, crop_left + target_width, height)
page.set_cropbox(new_rect)
doc.save(output_path)
#python crop-pdf-ipadmini.py input.pdf output.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment