Copy link to clipboard
Copied
Hey everybody,
I need to store the formatted contents of a text frame in a variable, so I can then insert it into another text frame dynamically. I've tried using the ".contents" property, but that doesn't carry over the font, color, size, etc. I can show my code if that would help you understand my question better!
Thanks for the help!
Sam
Hi Sam,
I think, you did not understand the difference between the value of the contents property and the value of the texts property of a text frame (or any other object that share the two properties).
Formatted text can be accessed with object text.
It's the direct reference to formatted text in a document.
Here an example:
app.documents[0].textFrames[0].texts[0];
Here another one:
app.documents[0].textFrames[0].parentStory.texts[0];
The difference between the two lines:
If the text frame has overset t
Copy link to clipboard
Copied
Hi,
The question is not how to store but when and where use it, I think?
For example - if your goal is to duplicate some part of formatted text
(in other place of this textFrame, other textFrame, other doc)
you can use method:
myText.duplicate (to: LocationOptions[, reference: varies])
Jarek
Copy link to clipboard
Copied
Thanks for the response Jarek!
Pardon my ignorance, but you could explain how exactly would I use that method in the following scenario?
var content = {};
var docRef = app.documents.item(0);
var frameCount = docRef.textFrames.count();
// Storing formatted text in Javascript object for use later
for (var i=0; i < frameCount; i++){
var frame = docRef.textFrames.item(i);
content[frame.id] = {};
content[frame.id]['content'] = frame.contents;
//Empty frame for PDF export
frame.contents = "";
}
// Export the document as PDF //
// Replace Text Frame Content
for (var i=0; i < frameCount; i++){
var frame = docRef.textFrames.item(i);
frame.contents = content[frame.id]['content'];
}
Copy link to clipboard
Copied
Hi Sam,
I think, you did not understand the difference between the value of the contents property and the value of the texts property of a text frame (or any other object that share the two properties).
Formatted text can be accessed with object text.
It's the direct reference to formatted text in a document.
Here an example:
app.documents[0].textFrames[0].texts[0];
Here another one:
app.documents[0].textFrames[0].parentStory.texts[0];
The difference between the two lines:
If the text frame has overset text, you'll get the overset text plus the one visible in the text frame with the second line.
Or if the text frames is threaded with another one sharing one story, again you'll get the whole formatted text with the second line.
And formatted text will also mean: You'll get all anchored frames if there are some. Also tables.
You can move or duplicate texts objects to e.g. an insertion point. One example with method move():
app.documents[0].textFrames[0].texts[0].move( LocationOptions.AFTER , app.documents[0].textFrames[1].insertionPoints[0] );
Just experiment a bit with two text frames in a document to get used to it.
Also see e.g. here:
Adobe InDesign CS6 (8.0) Object Model JS: Text
Regards,
Uwe
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more