Skip to content

Instantly share code, notes, and snippets.

@Splines
Created April 16, 2024 16:42
Show Gist options
  • Save Splines/391ceb88a98ff73dacb1a4fb6ffaec1f to your computer and use it in GitHub Desktop.
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.
# 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