diff --git a/Split.py b/Split.py index 06f6fe1..22a28e3 100644 --- a/Split.py +++ b/Split.py @@ -1,22 +1,22 @@ -from PyPDF2 import PdfFileWriter, PdfFileReader +from PyPDF2 import PdfWriter, PdfReader import os, errno filename = "long-sample.pdf" directory = "splitted/"+filename def split(directory, filename): - inputpdf = PdfFileReader(open(filename, "rb")) + inputpdf = PdfReader(open(filename, "rb")) try: os.makedirs(directory) except OSError as e: if e.errno != errno.EEXIST: raise - for i in range(inputpdf.numPages): - output = PdfFileWriter() - output.addPage(inputpdf.getPage(i)) + for i in range(len(inputpdf.pages)): + output = PdfWriter() + output.add_page(inputpdf.pages[i]) with open(directory+ "/%s.pdf" % i, "wb") as outputStream: output.write(outputStream) if __name__ == "__main__": - split(directory, filename) \ No newline at end of file + split(directory, filename) diff --git a/main.py b/main.py index dd37ede..c82b2c8 100644 --- a/main.py +++ b/main.py @@ -11,12 +11,12 @@ Split.split(directory, filename) pdfFileObj = open(filename, 'rb') - pdfReader = PyPDF2.PdfFileReader(pdfFileObj) + pdfReader = PyPDF2.PdfReader(pdfFileObj) - for i in range(pdfReader.numPages): + for i in range(len(pdfReader.pages)): splitted_file_name = directory + "/" + repr(i) call(["pdftotext", splitted_file_name + ".pdf"]) - # f = open(splitted_file_name + '.txt', 'r') - # print("Page %s" % repr(i+1)) - # print(f.read()) - # print("====================") \ No newline at end of file + f = open(splitted_file_name + '.txt', 'r') + print("Page %s" % repr(i+1)) + print(f.read()) + print("====================")