Sunday, November 6, 2011

Viewing Text Items


Use the GetText() method to work with the content of paragraphs or other objects that contain text. The method takes a single parameter that indicates the type of text items you are interested in. There is a long list of possibilities. See the Scripting Guide for full details. The method returns an array of text items.

The example that follows request text items in the main flow and request the following item types:
  • Indicators of places where the character properties of the text change. (FTI_CharPropsChange)
  • The identifier of the paragraph or text line to which the offset of each text items in the array is calculated. (FTI_TextObjId)
  • The strings that make up the text. (FTI_String)
Why is it important to know the identifier of the object containing the text? While the code queries the flow, making any changes requires knowing the identifier of the paragraph (or text line) in which the text resides.

What about the text strings? If I run my script on a paragraph that has no changes to character properties will I get a single string? The answer is maybe. The FDK has a string limit size of 255 so no string will be larger than 255 characters. But, there is no guarantee that the text items will have the largest supported string size consistent with the information requested. In fact, if you call GetText() on a file that has been heavily edited, it is likely that you will get back a number of smaller text strings. There may be other reasons for this phenomenon that are not apparent to those not privy to the internal workings of the FrameMaker product. In short, GetText() gives you all of the text strings in their order of appearance but there is no guarantee that the number of text items is minimal.

Imagine that GetText() is run, as shown in the code that follows, on the document below. The call is followed by a request that the text items found be displayed in the FrameMaker console.

NOTE: The constant values or OR'd to produce the appropriate flag parameter.

var tItems = mainflow.GetText(Constants.FTI_CharPropsChange | Constants.FTI_TextObjId |
Constants.FTI_String); 
PrintTextItems(tItems);

The file



The text items


The first number displayed is the offset from the paragraph start. In the case of FTI_TextObjId, you see the actual object identifier. In the case of FTI_CharPropsChange, the hex value indicates the type of change that took place. FTI_String items are followed by the actual string text.

No comments:

Post a Comment