Monday, October 17, 2011

Working with Paragraph Formats

A paragraph's format can updated by setting its Name property to a new value.That action changes the name of the paragraph format but it does not add a new paragraph format to the catalog. (If the new format already exists, that catalog format would be used.)

It is possible to programmatically add new formats to the catalog using a script. Paragraph formats are "named" objects. In the FDK, F_ApiNewNamedObject() can be used to create one. In ExtendScript, you need to use NewNamedObject() and pass in the object type and the name for the new object.

A paragraph format created in this way has a default set of properties. You can set the properties to the desired state one at a time. In a later post, I will discuss other ways to give an object a desired set of properties.

In summary, this example creates a new paragraph format named Para and then changes any paragraph in the main flow with the format Body to the format Para

var doc = app.ActiveDoc;
var tframe = doc.MainFlowInDoc.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;

//create a new paragraph format
var pgfFmt = doc.NewNamedObject(Constants.FO_PgfFmt, "Para");

while (pgf.ObjectValid()) {
    if ( pgf.Name =="Body")
        pgf.Name = "Para";
    pgf = pgf.NextPgfInFlow;
    }

No comments:

Post a Comment