感谢this great answer我能够弄清楚如何使用 Python 和 InDesign 脚本 API 对我的文档运行预检。现在我想自动调整溢出文本框的文本大小,但无法弄清楚如何从 Preflight 对象中检索 TextBox 对象。
我提到了API specification ,但所有属性似乎只产生不唯一定义文本框的字符串,如本例所示:
Errors Found (1):
Text Frame (R=2)
是否有任何方法可以从预检中检索违规对象,以便稍后对其进行操作?我非常感谢您对此事提供更多意见,因为我陷入了困境!
最佳答案
如果您需要的只是查找并修复溢出错误,我建议使用此解决方案:
这是修复文本溢出错误的简单扩展脚本。它减小了事件文档中所有溢出文本框架的字体大小:
var doc = app.activeDocument;
var frames = doc.textFrames.everyItem().getElements();
var f = frames.length
while(f--) {
var frame = frames[f];
if (frame.overflows) resize_font(frame)
}
function resize_font(frame) {
app.scriptPreferences.enableRedraw = false;
while (frame.overflows) {
var texts = frame.parentStory.texts.everyItem().getElements();
var t = texts.length;
while(t--) {
var characters = texts[t].characters.everyItem().getElements();
var c = characters.length;
while (c--) characters[c].pointSize = characters[c].pointSize * .99;
}
}
app.scriptPreferences.enableRedraw = true;
}
您可以将其保存在任何文件夹中并通过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()
errors = process.processResults
print('Errors:', errors)
if errors[:4] != 'None':
script = r'd:\temp\fix_overset.jsx' # <-- here is the script to fix overset
print('Run script', script)
app.DoScript(script, 1246973031) # run the jsx script
# 1246973031 --> ScriptLanguage.JAVASCRIPT
# https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ScriptLanguage.html
process = app.PreflightProcesses.Add(doc, profile)
process.WaitForProcess()
errors = process.processResults
print('Errors:', errors) # it should print 'None'
if errors[:4] == 'None':
doc.Save()
doc.Close()
input('\nDone... Press <ENTER> to close the window')
关于Python InDesign 脚本 : Get overflowing textbox from preflight for automatic resizing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70114267/