30 lines
766 B
Python
30 lines
766 B
Python
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()
|