InDesign服务器-更新文本框架内容导致丢失或额外的内容

InDesign Server - Updating text frame contents results in missing or extra content

本文关键字:文本 更新 框架 服务器 InDesign      更新时间:2023-09-26

我正在尝试使用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接口和我调用它的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总是省略我给它的最后一个单词。

另一个问题是,如果我给任何文本框架一个字符串,甚至中等长度,它被切断。如果我尝试将每个文本框的内容设置为"这里是一些很长的文本,不同的文本框将在不同的点切断。",结果如下:

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 "

奇怪的是,截断的文本将被"记住",并在下次运行脚本时作为垃圾重新注入,无论我传入什么。因此,如果我重新运行脚本并尝试将每个文本框架更改为非常短的内容,如"Spam",我将得到以下结果:

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时遇到了麻烦。内容取决于所涉及的文本框架的大小。尝试设置textframe.parentStory.contents