-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDF-Combiner.py
32 lines (22 loc) · 945 Bytes
/
PDF-Combiner.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
import PyPDF2
import os
# List of PDF files to combine
pdf_files = ["file1.pdf", "file2.pdf", "file3.pdf"] # Replace with the actual file paths of the PDFs you want to merge
# Create a PDF merger object
pdf_merger = PyPDF2.PdfMerger()
# Add each PDF to the merger
for pdf_file in pdf_files:
pdf_merger.append(pdf_file)
# Output file name
output_pdf_name = "PDF_combined.pdf" # Replace with the desired name for the merged PDF file
# Specify the output directory for the merged PDF file
output_directory = "/path/to/output/directory/" # Replace with your desired output directory path
# Ensure the output directory exists or create it
os.makedirs(output_directory, exist_ok=True)
# Create the full output PDF file path
output_pdf = os.path.join(output_directory, output_pdf_name)
# Write the merged PDF to the output file
pdf_merger.write(output_pdf)
# Close the merger
pdf_merger.close()
print(f"PDFs merged into {output_pdf}")