python - Python InDesign 脚本:如何运行预检检查?
问题描述
本指南很好地概述了使用 Python 编写 InDesign 脚本。我可以打开我的文档并将其导出为 PDF,但除此之外,我还想检查是否有任何文本框有一些溢出的文本。我想使用一些预检检查来完成此操作,但是当我尝试调用时
myPreflight = app.PreflightProcesses.add(myDocument, myProfile)
我收到错误“缺少方法'Add'的必需参数'TargetObject'。”,尽管根据文档我确实提供了目标对象。
我非常感谢一个关于如何检查溢出文本的具体示例,因为我对这种方法相当陌生。感谢您的时间!
解决方案
这是适用于我的 Python 代码段:
import win32com.client
app = win32com.client.Dispatch('InDesign.Application.CS6')
doc = app.Open(r'd:\temp\test.indd')
profile = app.PreflightProfiles.Item('Stackoverflow 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('Stackoverflow Profile');
var myPreflight = app.preflightProcesses.add(myDocument, myProfile);
myPreflight.waitForProcess();
var results = (myPreflight.processResults);
alert(results);
推荐阅读
- python - 如何使用matplotlib在python中绘制实变量的复值函数
- r - 如何转换我的日期成为行条目而不是一列日期的数据框?
- java - Jackson 对象映射器没有从 java 对象创建正确的 Json 字符串
- node.js - 迭代数据并将其推送到数组后数组为空
- heroku - 如何在heroku上安装steamcmd?
- node.js - 在 Node.js Cloud Functions 中将 Firebase 时间戳设置为从今天起 2 周
- forms - 如何创建重定向到页面的搜索框?
- java - 如何解决此问题:失败 - 应用程序已存在于路径 /second
- machine-learning - 难以理解权重矩阵或 theta 矩阵的维度是 3X4 吗?
- python - 在python中创建一个矩阵,使得每个元素都是一个四元数