【问题标题】:InDesign Server - Updating text frame contents results in missing or extra contentInDesign Server - 更新文本框架内容会导致内容丢失或多余
【发布时间】:2014-06-05 08:11:54
【问题描述】:

我正在尝试使用 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 "

奇怪的是,下一次我在传入的任何内容的末尾将脚本作为垃圾运行时,截断的文本将被“记住”并重新注入。因此,如果我然后重新运行脚本并尝试将每个文本框更改为非常短的内容,例如“垃圾邮件”,我得到以下结果:

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 将文本框更改为我给它的任何内容?

【问题讨论】:

    标签: javascript adobe-indesign indesign-server


    【解决方案1】:

    我在使用 textframe.contents 时遇到了麻烦,具体取决于所涉及的文本框的大小。尝试设置 textframe.parentStory.contents。

    【讨论】:

    • 像魅力一样工作。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多