西麦农场

时间尺度守恒


  • 首页

  • 分类

  • 归档

  • 坑List

macOS中自动化批量将Word文档导出为PDF

2019-02-14 | DevFAQ | macOS 自动化 Word PDF

说明

业务需求,需要在手机端(web)显示ppt或者word文档,第一版考虑使用PDF显示,可在手机端使用js直接解析pdf性能糟糕,查看或者翻页不够流畅,立马考虑使用图片来代替PDF。
1.macOS中自动化批量将PPT文档导出为PDF
2.macOS中自动化批量将PDF文档导出为图片

前置条件

电脑上必须安装 Microsoft Word软件

操作步骤

  • 打开自动操作,新建『工作流程』
  • 将『操作>文件和文件夹>获取指定的访达项目』拖到操作区域,或者直接选择一个Word文件拖动到操作区域。
  • 将『操作>实用工具>运行AppleScript』拖到操作区域,复制一下代码
  1. property theList : {"doc", "docx"}
  2. on run {input, parameters}
  3. set output to {}
  4. tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
  5. repeat with x in input
  6. try
  7. set theDoc to contents of x
  8. tell application "Finder"
  9. set theFilePath to container of theDoc as text
  10. set ext to name extension of theDoc
  11. if ext is in theList then
  12. set theName to name of theDoc
  13. copy length of theName to l
  14. copy length of ext to exl
  15. set n to l - exl - 1
  16. copy characters 1 through n of theName as string to theFilename
  17. set theFilename to theFilename & ".pdf"
  18. tell application "Microsoft Word"
  19. set default file path file path type documents path path theFilePath
  20. open theDoc
  21. set theActiveDoc to the active document
  22. save as theActiveDoc file format format PDF file name theFilename
  23. copy (POSIX path of (theFilePath & theFilename as string)) to end of output
  24. close theActiveDoc
  25. end tell
  26. end if
  27. end tell
  28. end try
  29. end repeat
  30. tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
  31. return output
  32. end run
  • 将『操作>文件和文件夹>移动访达项目』拖到操作区域,选择要输出的目录。
  • 在『获取指定的访达项目』中选择想要导出为PDF文件的Word文件。点击运行即可。
    macOS中自动化批量将Word文档导出为PDF

    使用中的问题

  1. 脚本问题,每次多个个文件导出时第一个总不能成功导出。
  • 目录
  • 站点概览
  • 说明
  • 前置条件
  • 操作步骤
  • 使用中的问题
    戊在西安填坑中

    戊在西安填坑中

    29 日志
    7 分类
    50 标签
    0%
    © 2017- 戊在西安填坑中 | 陕ICP备13008306号-3 | 主题 NexT.Pisces