Skill-BidCreater/scripts/export_docx_pdf.py
2026-03-09 22:20:38 +08:00

30 lines
766 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import argparse
import shutil
import subprocess
from pathlib import Path
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--docx", required=True)
parser.add_argument("--outdir", required=True)
args = parser.parse_args()
soffice = shutil.which("soffice")
if not soffice:
raise FileNotFoundError("未检测到 LibreOffice/soffice无法导出 PDF。")
docx_path = Path(args.docx).resolve()
out_dir = Path(args.outdir).resolve()
out_dir.mkdir(parents=True, exist_ok=True)
subprocess.run(
[soffice, "--headless", "--convert-to", "pdf", "--outdir", str(out_dir), str(docx_path)],
check=True,
)
if __name__ == "__main__":
main()