from pathlib import Path from pypdf import PdfWriter def merge_pdfs(pdfs: list[Path], out_path: Path) -> Path: writer = PdfWriter() for pdf in pdfs: writer.append(str(pdf)) out_path.parent.mkdir(parents=True, exist_ok=True) with out_path.open("wb") as f: writer.write(f) writer.close() return out_path