Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyPDF2 import PdfFileWriter, PdfFileReader
- import sys
- import os
- #directoryout = 0
- class EP:
- # Drag a pdf file to this script and it will separate the pages and put them in their own direcrtory
- def extract_pages(self, path):
- self.pdfpath = path
- inputpdf = PdfFileReader(open(path, "rb"))
- self.inputpdf = inputpdf
- # Directory path is the same name as the file without the extention
- self.directoryout = path.strip('.pdf')
- os.mkdir(self.directoryout)
- for i in range(inputpdf.numPages):
- output = PdfFileWriter()
- output.addPage(inputpdf.getPage(i))
- with open("%s\\document-page%s.pdf" % (self.directoryout, i+1), "wb") as outputStream:
- output.write(outputStream)
- if __name__ == "__main__":
- a=EP()
- a.extract_pages(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement