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.

Revisions

  1. Splines created this gist Apr 16, 2024.
    19 changes: 19 additions & 0 deletions increase-pdf-margins.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # 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}")