Skip to content

Instantly share code, notes, and snippets.

@danielfeitopin
Created August 3, 2024 21:24
Show Gist options
  • Save danielfeitopin/82a34c954650590a906f3dc6faacdc0c to your computer and use it in GitHub Desktop.
Save danielfeitopin/82a34c954650590a906f3dc6faacdc0c to your computer and use it in GitHub Desktop.
Script to extract pages from a PDF.
from pypdf import PdfReader, PdfWriter
PDF_IN = '' # CHANGE
PDF_OUT = '' # CHANGE
PAGES = [] # Starting at 1
reader = PdfReader(PDF_IN)
writer = PdfWriter()
for page in PAGES:
writer.add_page(reader.pages[page - 1])
with open(PDF_OUT, "wb") as f:
writer.write(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment