I'm trying to update a series of textframes using InDesign Server's SOAP API. When I try to change the contents of a textframe, the result that comes back sometimes has missing or extra content.
Here's the function I'm using to update the textframes:
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;
}
}
}
Each time the script is run, it opens the document, makes the changes, saves the document, generates a JPG preview image and closes the document. To isolate this problem away from the SOAP interface and the PHP script I'm calling it from, I am passing no parameters into the script and am simply using string literals in the JS to pass in the new text.
So, if I update a series of textframes like this:
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");
Under normal circumstances the result I get is this:
601: "Some text here"
550: "Some text "
527: "Some text here"
504: "Some text here"
466: "Some text here"
Textframe 550 always omits the last word of whatever I give it.
The other problem is that if I give any text frame a string of even moderate length, it gets chopped off. If I try to set the contents of each text frame to "Here is some very long text which different textframes will cut off at different points.", the result is as follows:
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 "
What's weird is that the cut-off text will be "remembered" and re-injected next time I run the script as junk on the end of whatever I pass in. So if I then re-run the script and try to change each text frame to something really short, like "Spam", I get the following results:
601: "Spamtext which different "
550: "Spamwhich different "
527: "Spamcut off at different points."
504: "Spamvery "
466: "Spamvery long text "
And if I try to run it again, I get this:
601: "Spamtextframes will cut "
550: ""
527: "Spam"
504: "Spamlong "
466: "Spamwhich "
And so on, until it runs out of old text.
This problem persists even if I restart IDS, so (I guess) it must be saved into the document somehow.
As I was running the script just now to test IDS restarts, when I flushed all the old text, textframe 504 started skipping the last word of each submission as well...
Any idea what is causing this behaviour and how I can just get IDS to change the textframes to whatever I give it?
I have had trouble using textframe.contents depending on the size of the textframes involved. Try setting textframe.parentStory.contents instead.