1from PyPDF2 import PdfFileWriter, PdfFileReader
2
3inputpdf = PdfFileReader(open("document.pdf", "rb"))
4
5for i in range(inputpdf.numPages):
6 output = PdfFileWriter()
7 output.addPage(inputpdf.getPage(i))
8 with open("document-page%s.pdf" % i, "wb") as outputStream:
9 output.write(outputStream)
10
1# pdf_splitting.py
2
3from PyPDF2 import PdfFileReader, PdfFileWriter
4
5def split(path, name_of_split):
6 pdf = PdfFileReader(path)
7 for page in range(pdf.getNumPages()):
8 pdf_writer = PdfFileWriter()
9 pdf_writer.addPage(pdf.getPage(page))
10
11 output = f'{name_of_split}{page}.pdf'
12 with open(output, 'wb') as output_pdf:
13 pdf_writer.write(output_pdf)
14
15if __name__ == '__main__':
16 path = 'Jupyter_Notebook_An_Introduction.pdf'
17 split(path, 'jupyter_page')
18