首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于将docx导出到pdf的MacOS Automator + Applescript解决方案

用于将docx导出到pdf的MacOS Automator + Applescript解决方案
EN

Stack Overflow用户
提问于 2018-08-14 15:03:48
回答 2查看 5.7K关注 0票数 5

在阅读了很多不同的线程之后,我抓挠了一下头,尝试了一堆脚本,但似乎都没有用。

我想使用Automator自动Word 2016转换一个选择的docx文件为pdf。

使用下列自动服务:

使用了以下脚本:

代码语言:javascript
复制
on run {input, parameters}
    tell application id "com.microsoft.Word"
        activate
        open input
        set doc to name of active window
        set theOutputPath to (input & ".pdf")
        save as active document file name theOutputPath file format format PDF
    end tell
end run

这会导致错误:Microsoft Word获得了一个错误: active document不理解“另存为”消息.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-14 15:39:50

主要问题是input是一个列表。您必须使用一个重复循环分别处理每个文件。

我添加了一行,以在转换后关闭当前文档。

代码语言:javascript
复制
on run {input, parameters}
    tell application id "com.microsoft.Word"
        activate
        repeat with aFile in input
            open aFile
            set theOutputPath to ((aFile as text) & ".pdf")
            tell active document
                save as it file name theOutputPath file format format PDF
                close saving no
            end tell
        end repeat
    end tell
end run
票数 7
EN

Stack Overflow用户

发布于 2018-09-09 14:40:20

为了防止@vadian的答案中讨论的问题,首先将文件保存到Word的默认文件夹(通常是~/Library/Containers/com.microsoft.Word/Data/Documents) ),然后将文件移到其他地方。

代码语言:javascript
复制
on run {input, parameters}
    repeat with aFile in input
        tell application "System Events"
            set inputFile to disk item (aFile as text)
            set outputFileName to (((name of inputFile) as text) & ".pdf")
        end tell

        tell application id "com.microsoft.Word"
            activate
            open aFile
            tell active document
                save as it file name outputFileName file format format PDF
                close saving no
            end tell
            set defaultPath to get default file path file path type documents path
        end tell

        tell application "System Events"
            set outputPath to (container of inputFile)
            set outputFile to disk item outputFileName of folder defaultPath
            move outputFile to outputPath
        end tell
    end repeat
    return input
end run
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51844514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档