Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Set TextFrame contents with formatted text

New Here ,
Aug 13, 2017 Aug 13, 2017

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

TOPICS
Scripting
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 14, 2017 Aug 14, 2017

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

...
Translate
Mentor ,
Aug 14, 2017 Aug 14, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2017 Aug 14, 2017

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'];

   }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 14, 2017 Aug 14, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines