-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesclar_pdfs.py
34 lines (28 loc) · 1.04 KB
/
mesclar_pdfs.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
import PyPDF2
import PySimpleGUI as sg
import os
sg.theme('Dark Blue 3')
layout = [
[sg.Text('Pasta: '), sg.InputText(key='entrada', disabled=True),
sg.FolderBrowse('...')],
[sg.Text('Saída: '), sg.InputText(key='saida', disabled=True),
sg.FileSaveAs('...', file_types=(('PDF', '.pdf'),))],
[sg.Button('Combinar'), sg.Button('Sair')]
]
window = sg.Window('Combinar arquivos PDF', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Sair':
break
elif event == 'Combinar':
pasta = values['entrada']
if pasta.endswith('\\') or pasta.endswith('/'):
pasta = pasta[:-1]
arquivos = os.listdir(pasta)
arquivos.sort()
with PyPDF2.PdfMerger() as merger:
for arquivo in arquivos:
if os.path.isfile(f'{pasta}/{arquivo}') and arquivo.lower().endswith('.pdf'):
merger.append(f'{pasta}/{arquivo}')
merger.write(values['saida'])
window.close()