-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDFmerger.py
More file actions
37 lines (30 loc) · 1.02 KB
/
PDFmerger.py
File metadata and controls
37 lines (30 loc) · 1.02 KB
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
from PyPDF2 import PdfMerger
def merge_pdfs(pdf_list, output_path="merged_output.pdf"):
merger = PdfMerger()
for pdf in pdf_list:
try:
merger.append(pdf)
print(f"Added: {pdf}")
except Exception as e:
print(f"Error adding {pdf}: {e}")
merger.write(output_path)
merger.close()
print(f"\n✅ Merged PDF saved as: {output_path}")
if __name__ == "__main__":
print("Enter paths to PDFs you want to merge.")
print("Enter an empty line to finish.\n")
files = []
while True:
path = input("PDF path: ").strip().strip('"')
if path == "":
break
files.append(path)
if not files:
print("No files entered. Exiting.")
else:
output_name = input("\nEnter output file name (default merged_output.pdf): ").strip()
if output_name == "":
output_name = "merged_output.pdf"
if not output_name.endswith(".pdf"):
output_name += ".pdf"
merge_pdfs(files, output_name)