Created
October 15, 2020 15:58
-
-
Save ivansaul/8d434be2abc2bb37d89ce92add6a9b17 to your computer and use it in GitHub Desktop.
Split PDF by range with Python v3.x and pypdf2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
#split range | |
pgi=30 #start | |
pgf=37 #end | |
pdf_document = "test.pdf" | |
pdf = PdfFileReader(pdf_document) | |
pdf_writer = PdfFileWriter() | |
for page in range(pgi-1,pgf): | |
current_page = pdf.getPage(page) | |
pdf_writer.addPage(current_page) | |
with open(f'test-{pgi}-{pgf}.pdf', "wb") as out: | |
pdf_writer.write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment