Created
July 13, 2025 19:15
-
-
Save edykim/8dbeb90e929b698df1314e95a06c1dba to your computer and use it in GitHub Desktop.
crop pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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