Initial commit
This commit is contained in:
commit
cf83801dd1
5 changed files with 110 additions and 0 deletions
27
merge_pdfs.py
Normal file
27
merge_pdfs.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from PyPDF2 import PdfMerger
|
||||
|
||||
def merge_pdfs(output_path, input_paths):
|
||||
merger = PdfMerger()
|
||||
for pdf in input_paths:
|
||||
try:
|
||||
merger.append(pdf)
|
||||
print(f"Added: {pdf}")
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File not found - {pdf}")
|
||||
except Exception as e:
|
||||
print(f"Error adding {pdf}: {e}")
|
||||
merger.write(output_path)
|
||||
merger.close()
|
||||
print(f"Merged PDF saved as: {output_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python merge_pdfs.py output.pdf file1.pdf file2.pdf [file3.pdf ...]")
|
||||
sys.exit(1)
|
||||
|
||||
output_pdf = sys.argv[1]
|
||||
input_pdfs = sys.argv[2:]
|
||||
merge_pdfs(output_pdf, input_pdfs)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue