-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfSpider.py
44 lines (36 loc) · 1.4 KB
/
pdfSpider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fileHelper as fh
import sys
from PyPDF2 import PdfFileReader, PdfFileMerger
class PDFSpider:
module_name = ""
base_path = ""
is_blank_page_divided = False
blank_path = "blank.pdf"
emptyPdf = None
def __init__(self, module, base_path, is_blank_page_divided = '0'):
sys.setrecursionlimit(100000)
PDFSpider.module_name = module
PDFSpider.base_path = base_path
if is_blank_page_divided:
if is_blank_page_divided == '1':
PDFSpider.is_blank_page_divided = True
elif is_blank_page_divided == '0':
PDFSpider.is_blank_page_divided = False
PDFSpider.boot()
@staticmethod
def boot():
fh.create_project_dir(PDFSpider.module_name)
merger = PdfFileMerger()
files = fh.get_pdf_list_from_directory(PDFSpider.base_path)
if(PDFSpider.is_blank_page_divided):
# with open(PDFSpider.blank_path, "rb") as f:
PDFSpider.emptyPdf = PdfFileReader(open(PDFSpider.blank_path, "rb"))
for f in files:
print(f)
file = open(f, "rb")
merger.append(PdfFileReader(file))
if (PDFSpider.is_blank_page_divided):
merger.append(PDFSpider.emptyPdf)
file.close()
with open(PDFSpider.module_name + "/" + PDFSpider.module_name + ".pdf", 'wb') as modDir:
merger.write(modDir)