Skip to content

Instantly share code, notes, and snippets.

@dustinknopoff
Created December 20, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinknopoff/a86ee89775d74e3a0ee0e72e179ef967 to your computer and use it in GitHub Desktop.
Save dustinknopoff/a86ee89775d74e3a0ee0e72e179ef967 to your computer and use it in GitHub Desktop.
Split pdf into separate pages
# Answer from https://stackoverflow.com/a/490203
from PyPDF2 import PdfFileWriter, PdfFileReader
inputpdf = PdfFileReader(open("document.pdf", "rb"))
for i in range(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(i))
with open("document-page%s.pdf" % i, "wb") as outputStream:
output.write(outputStream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment