Mac 使用 Microsoft Word 批量将 DOCX 转 PDF(保持原排版)

Mac 使用 Microsoft Word 批量将 DOCX 转 PDF(保持原排版)

之前尝试过使用 WPS 和 LibreOffice 批量转换 DOCX 为 PDF,但发现导出的 PDF 存在页边距变大、上下留白增加、分页错乱等问题。

如果 Mac 已安装 Microsoft Word,可以直接通过 AppleScript 调用 Word 导出 PDF,生成效果与 Word 手动导出基本一致。

单个文件转换

bash 复制代码
osascript <<'EOF'
tell application "Microsoft Word"
    open POSIX file "/Users/mac/Downloads/1/1.docx"
    set d to active document
    save as d file name "/Users/mac/Downloads/1/1.pdf" file format format PDF
    close d saving no
end tell
EOF

批量转换整个目录

例如需要转换:

text 复制代码
/Users/mac/Downloads/1

目录下所有 .docx 文件:

bash 复制代码
DIR="/Users/mac/Downloads/1"

for f in "$DIR"/*.docx; do
    [ -f "$f" ] || continue

    pdf="${f%.docx}.pdf"

    osascript <<EOF
tell application "Microsoft Word"
    open POSIX file "$f"
    set d to active document
    save as d file name "$pdf" file format format PDF
    close d saving no
end tell
EOF

    echo "Converted: $(basename "$f")"
done

转换后:

text 复制代码
1.docx  ->  1.pdf
2.docx  ->  2.pdf
3.docx  ->  3.pdf

PDF 会保存在原文件所在目录。

适用场景

  • 合同
  • 标书
  • 论文
  • 公司模板
  • 对 PDF 排版一致性要求较高的文档

相比 WPS、LibreOffice 转换,直接调用 Microsoft Word 导出的 PDF 更能保持原始排版。

相关推荐
777VG5 小时前
PostgreSQL +martin将多张表输出成一个 MVT
前端·数据库·postgresql
mayaairi6 小时前
JS循环语句深度解析:嵌套for、while与do...while
开发语言·前端·javascript
To_OC6 小时前
啃完流式输出:从一个卡顿的 LLM 接口开始,我搞懂了数据流到底怎么 “流”
前端·javascript·llm
阳光是sunny6 小时前
LangGraph实战教程:defer延迟节点——让收尾工作自动排到最后
前端·人工智能·后端
kyriewen7 小时前
我用了三周Claude Code Skills——总结出5条铁律,第3条最反直觉
前端·ai编程·claude
阳光是sunny7 小时前
LangGraph实战教程:控制流详解
前端·人工智能·后端
格尔曼Noah8 小时前
Safari浏览器中如何只允许指定网站下载
前端·safari
用户059540174468 小时前
用了3年Redis,才发现我一直没搞懂缓存一致性测试
前端·css
swipe9 小时前
07|(前端转后全栈)为什么后端也要缓存?从前端缓存思维理解 Redis
前端·后端·全栈
IT小盘9 小时前
05-企业项目统一接入多个大模型-适配器模式实战
前端·人工智能·适配器模式