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 更能保持原始排版。

相关推荐
程序员黑豆6 小时前
Java类型推断完全指南:从var到菱形运算符,掌握使用限制与最佳实践
java·前端·ai编程
To_OC7 小时前
踩了个 TS 的坑之后,我终于把 type 和 interface 掰明白了
前端·react.js·typescript
GreenTea7 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调
前端·后端·算法
浮生望7 小时前
前端API工程化:用 Mock 数据与 Axios 配置实现独立于后端的并行开发
前端
万少8 小时前
给 DeepSeek Harness 装个"应用商店":一条命令,595 个插件随你逛
前端·javascript·后端
波波0078 小时前
C# 15 重磅新特性: 带标签 break 与 continue:重新定义嵌套循环控制流
服务器·前端·c#
Brown.alexis9 小时前
es6知识点1-自备使用
前端·ecmascript·es6
小爬的老粉丝10 小时前
JavaScript 纯前端预览 WPS:先识别容器,再路由解析器
前端·javascript·wps
计算机魔术师10 小时前
新兴多智能体系统的模式与问题
前端
用户0595401744611 小时前
AI Agent 上下文污染踩坑实录:用 pytest + Redis 揪出 3 类记忆串号 bug,排查 6 小时
前端·css