Pdf 使用AppleScript和Adobe Acrobat关闭文档
我正在尝试使用AppleScript和Adobe Acrobat Pro将数千个PDF转换为TXT。我的代码循环浏览每个PDF文件,打开它,并将其保存为TXT。这部分工作正常:PDF转换为TXT,没有问题。我不知道该怎么做的是如何在每个PDF保存为TXT后关闭它。PDF保持打开状态,最终我的内存耗尽(有很多PDF,其中一些很大) 这是我的代码:Pdf 使用AppleScript和Adobe Acrobat关闭文档,pdf,applescript,acrobat,Pdf,Applescript,Acrobat,我正在尝试使用AppleScript和Adobe Acrobat Pro将数千个PDF转换为TXT。我的代码循环浏览每个PDF文件,打开它,并将其保存为TXT。这部分工作正常:PDF转换为TXT,没有问题。我不知道该怎么做的是如何在每个PDF保存为TXT后关闭它。PDF保持打开状态,最终我的内存耗尽(有很多PDF,其中一些很大) 这是我的代码: set sourceFolder to "Macintosh HD:Users:thiagomarzagao:pdffolder" tell appl
set sourceFolder to "Macintosh HD:Users:thiagomarzagao:pdffolder"
tell application "Finder"
set fileSet to get every file of folder sourceFolder
end tell
tell application "Finder"
repeat with i from 1 to (count of fileSet)
set currentFile to (item i of fileSet) as string
set outFile to "Macintosh HD:Users:thiagomarzagao:txtfolder:" & "newfile" & i & ".txt"
with timeout of 6000 seconds
tell application "Adobe Acrobat Pro"
activate
open currentFile
save document i to file outFile using conversion "com.adobe.acrobat.plain-text"
close currentFile saving no
end tell
end timeout
end repeat
end tell
我得到:
error“Adobe Acrobat Pro出现错误:\“Macintosh HD:Users:thiagomarzagao:MyPdfile.pdf\”不理解“close”消息。“Macintosh HD:Users:thiagomarzagao:Desktop:MyPdfile.pdf”中的编号-1708
如果我将有问题的行替换为close document I saving no
或close every document saving no
我会得到以下结果:
error“Adobe Acrobat Pro出现错误:文档2不理解“保存”消息。文档2中的编号-1708
如果我尝试关闭窗口1
,我会得到以下结果:
error“Adobe Acrobat Pro出现错误:窗口1无法理解“关闭”消息。窗口1中的编号-1708
我做错了什么
< Adobe AcROCAT席Pro 110.23,MaOS高Sierra 107.4,Apple脚本2.7,脚本编辑器2.10(194)< /P> < P>混合HFS字符串路径和Adobe文档说明符,不可交换。 Acrobat有一个属性
活动文档
,可以用作前文档的引用
一些注意事项:
- 第二部分不需要查找器
- 我没有使用
而是将命名改为使用原始名称newFile12
- 脚本使用相对路径
- 有些PDF文件无法转换为文本,我添加了一个try块以忽略错误
set homeFolder to path to home folder as text
set sourceFolder to homeFolder & "pdffolder:"
set txtFolder to homeFolder & "txtfolder:"
tell application "Finder"
set fileSet to get every file of folder sourceFolder
end tell
activate application "Adobe Acrobat Pro"
repeat with aFile in fileSet
set currentFile to aFile as text
set currentFileName to name of aFile
set outFile to txtFolder & text 1 thru -5 of currentFileName & ".txt"
with timeout of 6000 seconds
tell application "Adobe Acrobat Pro"
open currentFile
try
save active doc to file outFile using conversion "com.adobe.acrobat.plain-text"
end try
close active doc saving no
end tell
end timeout
end repeat