Python InDesign 脚本:如何 运行 预检?

Python InDesign scripting: How to run a preflight check?

This guide 很好地概述了使用 Python 的 InDesign 脚本。我可以打开我的文档并将其导出为 PDF,但除此之外,我还想检查是否有任何文本框有一些溢出的文本。我想使用一些预检来完成此操作,但是当我尝试调用

myPreflight = app.PreflightProcesses.add(myDocument, myProfile)

我收到错误消息“缺少方法 'Add' 所需的参数 'TargetObject'。”,尽管根据 documentation 我确实提供了目标对象。

我非常希望能提供一个关于如何检查溢出文本的具体示例,因为我对这种方法还很陌生。感谢您的宝贵时间!

这是对我有用的 Python 片段:

import win32com.client

app = win32com.client.Dispatch('InDesign.Application.CS6')
doc = app.Open(r'd:\temp\test.indd')

profile = app.PreflightProfiles.Item('Whosebug Profile')
print('Profile name:', profile.name)

process = app.PreflightProcesses.Add(doc, profile)
process.WaitForProcess()
results = process.processResults
print('Results:', results)

doc.Close()

input('\nDone... Press <ENTER> to close the window')

对于我的测试文件,当它出现 'Overset Text' 错误时,它显示如下输出:

如果没有错误,我得到这个:

当然你需要把代码中的文件名和配置文件名改成你实际的文件名和配置文件名。也许您需要将 CS6 更改为 CC.2020 或您拥有的任何内容。

以防万一,代码的 ExtendScript 变体(对于已打开的文档)如下所示:

var myDocument = app.activeDocument;
var myProfile = app.preflightProfiles.item('Whosebug Profile');
var myPreflight = app.preflightProcesses.add(myDocument, myProfile);
myPreflight.waitForProcess();
var results = (myPreflight.processResults);
alert(results);