-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf_merger.py
40 lines (33 loc) · 1.47 KB
/
pdf_merger.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 os
from PyPDF2 import PdfFileMerger
from borb.pdf.pdf import PDF
from borb.pdf.document.document import Document
def do_merge_epta(path):
counter = 0
for pdf_letter in os.scandir(path):
counter += 1
merger = PdfFileMerger()
merger.append(os.path.join(path, pdf_letter.name))
merger.append('Приложение к письму оспаривание КС.pdf')
merger.write(os.path.join(path, f'letter_700_PP_{counter + 1}.pdf'))
merger.close()
print('Merged:', pdf_letter.name)
# for pdf_letter in os.scandir(path):
# counter += 1
#
# # Прочитайте первый PDF-файл
# with open(pdf_letter, "rb") as pdf_file_handle:
# input_pdf_001 = PDF.loads(pdf_file_handle)
#
# # Прочитайте второй PDF-файл
# with open("Приложение к письму оспаривание КС.pdf", "rb") as pdf_file_handle:
# input_pdf_002 = PDF.loads(pdf_file_handle)
#
# # Создайте новый PDF-файл, объединив два входных файла
# output_document = Document()
# output_document.append_document(input_pdf_001)
# output_document.append_document(input_pdf_002)
#
# # Написать PDF
# with open(os.path.join(path, f'letter_700_PP_{counter + 1}.pdf'), "wb") as pdf_out_handle:
# PDF.dumps(pdf_out_handle, output_document)