-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathpdfmerger.py
35 lines (22 loc) · 850 Bytes
/
pdfmerger.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
import PyPDF2
def merge_pdfs(output_filename, input_files):
pdf_merger = PyPDF2.PdfMerger()
for file in input_files:
try:
with open(file, 'rb') as pdf_file:
pdf_merger.append(pdf_file)
except FileNotFoundError:
print(f"Warning: File '{file}' not found. Skipping...")
with open(output_filename, 'wb') as output_file:
pdf_merger.write(output_file)
print(f"PDFs merged successfully! Output file: {output_filename}")
def main():
print("PDF Merge Tool")
print("Please enter the names of the two PDF files to merge:")
pdf1 = input("PDF 1: ")
pdf2 = input("PDF 2: ")
output_filename = input("Enter the name for the merged PDF: ")
input_files = [pdf1, pdf2]
merge_pdfs(output_filename, input_files)
if __name__ == "__main__":
main()