Created
August 18, 2022 06:11
-
-
Save dzonesasaki/cc780b91e4b5944796fc10bcea48ac27 to your computer and use it in GitHub Desktop.
splitting each pages for pdf file using 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
#!python3 | |
#splitpdf.py | |
#ref to : https://fastclassinfo.com/entry/python_pdf_split/ | |
import PyPDF2 | |
import sys | |
fnameL = 'a.pdf' | |
if len(sys.argv)>1: | |
fnameL = sys.argv[1] | |
print(fnameL) | |
orgpdf = PyPDF2.PdfFileReader(fnameL) | |
fnameHead = fnameL[:-4]+'_page_' | |
for k in range(orgpdf.numPages): | |
apdf = PyPDF2.PdfFileWriter() | |
apdf.addPage(orgpdf.getPage(k)) | |
fnames = fnameHead+'{0:03d}'.format(k)+'.pdf' | |
with open(fnames,'wb') as fid: | |
apdf.write(fid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment