Skip to content

Instantly share code, notes, and snippets.

@haider11234
Last active January 11, 2021 06:50
Show Gist options
  • Save haider11234/cbc0e2c8b0e21302b287586a7ee63153 to your computer and use it in GitHub Desktop.
Save haider11234/cbc0e2c8b0e21302b287586a7ee63153 to your computer and use it in GitHub Desktop.
#importing libraries
from PyPDF2 import PdfFileReader, PdfFileWriter
def split(path):
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
output = f'page{page}.pdf'
with open(output, 'wb') as output_pdf:
pdf_writer.write(output_pdf)
filename = 'sample.pdf'
split(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment