Skip to main content
Participant
April 17, 2023
Answered

Set TextFrame.contents to InDesign Tagged Text from variable

  • April 17, 2023
  • 1 reply
  • 265 views

Hi, scripting InDesign, I'm aware you can do this:

 

 

var doc = app.activeDocument;
var myTextFrame = doc.textFrames.add();
myTextFrame.contents = "whatever I want to put here";

 

 
But I'd like to set the contents to be some tagged text, so that we can colourise some of the words, this would be generated in a rest api and contained in the json response, so is it possible to do this:
 

 

/* Code to get data from api... */
var response = api.getData();

var doc = app.activeDocument;
var myTextFrame = doc.textFrames.add();
myTextFrame.contents = response.taggedText; // this just shows the tagged text, with all the markup etc...

 

 
Is this possible to do? Or do I need to write the file out to disk and then use TextFrame.place( File fileName, Boolean showingOptions, Object withProperties )?

 

This topic has been closed for replies.
Correct answer Manan Joshi

I don't think this is not possible without writing to disk. I suppose this is because unless we place a file the import handler for tagged text would not be triggered and hence it would be interpreted as plain text.

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
April 18, 2023

I don't think this is not possible without writing to disk. I suppose this is because unless we place a file the import handler for tagged text would not be triggered and hence it would be interpreted as plain text.

-Manan

-Manan