Created
January 19, 2024 17:25
-
-
Save BjornFJohansson/dfe0acfef0fd3b4113d5a985ac6d540c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/bjorn/miniforge3/envs/bjorn311/bin python3 | |
# -*- coding: utf-8 -*- | |
# https://pdfstandalone.com/en/merge-pdf | |
import sys | |
from pathlib import Path | |
from borb.pdf.document.document import Document | |
from borb.pdf.pdf import PDF | |
from tqdm import tqdm | |
script, *cliarg = sys.argv | |
pdfpaths = [Path(p) for p in cliarg] or sorted(Path(".").glob("*.pdf")) | |
output_document = Document() | |
outpath = Path("output.pdf") | |
try: | |
pdfpaths.remove(outpath) | |
except ValueError: | |
pass | |
for pdfpath in tqdm(pdfpaths): | |
with open(pdfpath, "rb") as pdf_file_handle: | |
pdf = PDF.loads(pdf_file_handle) | |
output_document.add_document(pdf) | |
with open(outpath, "wb") as pdf_out_handle: | |
PDF.dumps(pdf_out_handle, output_document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment