-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnePdfScanner.py
64 lines (45 loc) · 1.65 KB
/
OnePdfScanner.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
from Classes_and_Func.Scanner import *
from Classes_and_Func.QR import *
from Classes_and_Func.Stamper import *
from Classes_and_Func.Printer import *
from Classes_and_Func.PDF_Opener import *
from Classes_and_Func.get_time import *
from Classes_and_Func.QRParse import one_pdf_parser
from Exceptions.NotDocumentError import *
from collections import namedtuple
from Classes_and_Func.PagesFunc import *
import pdf2image
import colorama
import PyPDF2
colorama.init()
def connect(str_list):
"""Connect all strings of array"""
res = ""
for el in str_list:
res += el
return res
def get_file_name(filename):
"""Returns filename without extension"""
dot_array = filename.split(".")
res = ""
for el in dot_array[:-1]:
res += el
return res
def get_pdf_file_path(source_file_path):
"""Превращает путь до исходного файла в путь для конечного файла"""
return connect(source_file_path.split(".")[:-1]) + "_stamped-" + get_time() + ".pdf"
def main(file_path):
# Get pages texts
_, pdf_pages_texts = get_pages_texts_docs(file_path)
# Get PIL.Image of every pdf page
pdf_pages_images = get_pdf_images(file_path)
# get pages data
pages_data = get_pages_data(pdf_pages_texts)
stamped_pages_images = stamp_pages(pdf_pages_images, pages_data)
# List of images: Pdf's pages with QR and warning text
result_filename = get_pdf_file_path(source_file_path=file_path)
save_images_to_pdf(stamped_pages_images, result_filename, quality=75)
if __name__ == '__main__':
args = one_pdf_parser.parse_args()
main(args.file_path)