我正在尝试使用 InDesign Server 的 SOAP API 更新一系列文本框架。当我尝试更改文本框架的内容时,返回的结果有时会丢失或额外的内容。
这是我用来更新文本框架的函数:
function update_text(textframe_id, value) {
for (var i = 0; i < document.textFrames.length; i++) {
if (document.textFrames.item(i).id == textframe_id) {
var textframe = document.textFrames.item(i);
textframe.contents = value;
}
}
}
每次运行脚本时,它都会打开文档、进行更改、保存文档、生成 JPG 预览图像并关闭文档。为了将此问题与 SOAP 接口(interface)和我从中调用它的 PHP 脚本隔离开来,我没有向脚本中传递任何参数,而只是在 JS 中使用字符串文字来传递新文本。
所以,如果我像这样更新一系列文本框架:
update_text(601, "Some text here");
update_text(550, "Some text here");
update_text(527, "Some text here");
update_text(504, "Some text here");
update_text(466, "Some text here");
正常情况下我得到的结果是这样的:
601: "Some text here"
550: "Some text "
527: "Some text here"
504: "Some text here"
466: "Some text here"
Textframe 550 总是忽略我给出的最后一个单词。
另一个问题是,如果我给任何文本框架提供一个中等长度的字符串,它就会被 chop 。如果我尝试将每个文本框架的内容设置为“这是一些很长的文本,不同的文本框架将在不同的点 chop 。”,结果如下:
601: "Here is some very long "
550: "Here is some very long text "
527: "Here is some very long text which different textframes will "
504: "Here is some "
466: "Here is some "
奇怪的是,下次我在传入的内容末尾将脚本作为垃圾运行时, chop 文本将被“记住”并重新注入(inject)。因此,如果我重新运行脚本并尝试将每个文本框更改为非常短的内容,例如“垃圾邮件”,我得到以下结果:
601: "Spamtext which different "
550: "Spamwhich different "
527: "Spamcut off at different points."
504: "Spamvery "
466: "Spamvery long text "
如果我尝试再次运行它,我会得到以下结果:
601: "Spamtextframes will cut "
550: ""
527: "Spam"
504: "Spamlong "
466: "Spamwhich "
依此类推,直到用完旧文本。
即使我重新启动 IDS,这个问题仍然存在,所以(我猜)它必须以某种方式保存到文档中。
当我刚才运行脚本来测试 IDS 重新启动时,当我刷新所有旧文本时,textframe 504 也开始跳过每个提交的最后一个单词...
知道是什么导致了这种行为以及如何让 IDS 将文本框更改为我提供的任何内容吗?
最佳答案
我在使用 textframe.contents 时遇到了麻烦,具体取决于所涉及的文本框架的大小。尝试设置 textframe.parentStory.contents。
关于javascript - InDesign Server - 更新文本框架内容导致内容丢失或多余,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24054967/