gpt4 book ai didi

adobe-indesign - inDesign 脚本 : Get Text and Page number of Text styled with a certain Paragraph Style using JavaScript

转载 作者:行者123 更新时间:2023-12-04 05:28:14 27 4
gpt4 key购买 nike

我有一个包含 10 页文本的 inDesign 文档。文本使用不同的段落样式设置样式,其中一些与构建自定义目录相关。

有两个相关的段落样式,“Header1”和“Header2”,我试图从中构建自己的目录,我想将其导出到文本文件中。

我需要获取的相关信息是带有“Header1”和“Header2”样式的文本以及相应的页码。

我试图通过 GREP 实现这一点,并且成功了一半,但 GREP 扫描整个文档而不是一页一页地扫描。

有没有办法按段落样式逐页浏览所有样式文本?

提前致谢!

最佳答案

如果您不想使用 GREP,您可以遍历您感兴趣的故事的每个段落,收集应用了特定样式的段落。

在下面的示例代码中,我收集了 para_with_style 中的段落变量:

var doc = app.activeDocument;

var story = doc.stories[0];

// Get every paragraph in `story` (using `everyItem().getElements()` is more efficient)
var paras = story.paragraphs.everyItem().getElements();

// Collect every paragraph with a certain paragraph style
var applied_style = doc.paragraphStyles.itemByName('style-name');
var paras_with_style = [];
for (var i=0,l=paras.length; i<l; i++) {
var para = paras[i];
if (para.appliedParagraphStyle == applied_style) {
paras_with_style.push(para);
}
}

// Do something with each `para` in `paras_with_style`

关于adobe-indesign - inDesign 脚本 : Get Text and Page number of Text styled with a certain Paragraph Style using JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12937884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com