Created
April 16, 2024 16:42
-
-
Save Splines/391ceb88a98ff73dacb1a4fb6ffaec1f to your computer and use it in GitHub Desktop.
Add white margins to a PDF. Good to have some more space to take notes, e.g. in uni lectures.
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
# pip install pymupdf | |
import fitz | |
src = fitz.open("QM_SS24_Skript.pdf") | |
doc = fitz.open() | |
LEFT_MARGIN = 100 | |
RIGHT_MARGIN = 100 | |
for page in src: | |
width, height = page.rect.br | |
placement = fitz.Rect(LEFT_MARGIN, 0, width + LEFT_MARGIN, height) | |
newpage = doc.new_page(width=width + LEFT_MARGIN + RIGHT_MARGIN, | |
height=height) | |
newpage.show_pdf_page(placement, src, page.number) | |
doc.save(f"cropped {src.name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment