-
Notifications
You must be signed in to change notification settings - Fork 0
/
addFooter.py
47 lines (31 loc) · 1.22 KB
/
addFooter.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
import PyPDF2
def teste():
try:
# Especifica os arquivos
pdf_file = "input_document.pdf"
footer = "footer.pdf"
merged_file = "merged_document.pdf"
# Abre os pdf's
input_file = open(pdf_file, 'rb')
input_pdf = PyPDF2.PdfFileReader(input_file)
footer_file = open(footer, 'rb')
footer_pdf = PyPDF2.PdfFileReader(footer_file)
# Prepara o arquivo de saida
output = PyPDF2.PdfFileWriter()
page_count = input_pdf.getNumPages()
for page_number in range(page_count):
print(f"Adicionando footer: {page_number} de {page_count}")
# Pega a página do pdf
pdf_page = input_pdf.getPage(page_number)
# mescla o footer com a página do pdf
pdf_page.mergePage(footer_pdf.getPage(0))
# adiciona a página mesclada ao documento de saida
output.addPage(pdf_page)
merged_file = open(merged_file, 'wb')
output.write(merged_file)
merged_file.close()
footer_file.close()
input_file.close()
except Exception as e:
print(f'Erro ao adicionar footer:\n\n{e}\n\n')
teste()