Skip to main content
Inspiring
September 10, 2014
Question

Formatting text into styles

  • September 10, 2014
  • 2 replies
  • 566 views

Hi,

I need to find all formatting text into character styles, i used the below code. it's working fine.

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.fontStyle = "Bold"

app.changeTextPreferences.appliedCharacterStyle = "bold";

app.documents.item(0).changeText();

app.findTextPreferences.fontStyle = "Italic"

app.changeTextPreferences.appliedCharacterStyle = "italic";

app.documents.item(0).changeText();

app.findTextPreferences.fontStyle = "Bold Italic"

app.changeTextPreferences.appliedCharacterStyle = "bolditalic";

app.documents.item(0).changeText();

app.findTextPreferences.underline=true;

app.changeTextPreferences.appliedCharacterStyle = "underline";

app.documents.item(0).changeText();

app.findTextPreferences=app.changeTextPreferences=null;

alert("Characer Styles are applied for all Font styles")

Incase (Bold, Italic, Bold italic) + underline text comes, it will not work. so i created the character styles for boldwithunderline, italicwithunderline, bolditalicwithunderline.

Can you anyone please include the below condition?

Bold = "bold"

Italic = "italic"

Bold Italic = "bolditalic"

Normal text + underline = "underline"

Bold + underline = "boldunderline"

Italic + underline = "italicunderline"

Bold Italic + underline = "bolditalicunderline"

Is the below code is correct? if not please suggest.

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.fontStyle = "Bold"

app.changeTextPreferences.appliedCharacterStyle = "bold";

app.documents.item(0).changeText();

app.findTextPreferences.fontStyle = "Italic"

app.changeTextPreferences.appliedCharacterStyle = "italic";

app.documents.item(0).changeText();

app.findTextPreferences.fontStyle = "Bold Italic"

app.changeTextPreferences.appliedCharacterStyle = "bolditalic";

app.documents.item(0).changeText();

alert("Characer Styles are applied for all Font styles")

if((app.findTextPreferences.fontStyle = "Bold") &&  (app.findTextPreferences.underline=true) == true)

{

app.changeTextPreferences.appliedCharacterStyle = "boldunderline";

}

else if((app.findTextPreferences.fontStyle = "Italic") &&  (app.findTextPreferences.underline=true) == true)

{

app.changeTextPreferences.appliedCharacterStyle = "italicunderline";

}

else if((app.findTextPreferences.fontStyle = "Bold Italic") &&  (app.findTextPreferences.underline=true) == true)

{

app.changeTextPreferences.appliedCharacterStyle = "bolditalicunderline";

}

Regards,

Velu

This topic has been closed for replies.

2 replies

mdegamo
Inspiring
September 16, 2014

You have to list all possible properties and toggle each on/off for every instance.

You can have an array of objects to handle the mapping record.

Example:

var mapper = [

     {

          charStyle: 'bold-italic-underline',

          props: {

               fontStyle: 'Bold Italic',

               underline: true

          }

     }, {

          charStyle: 'bold-italic',

          props: {

               fontStyle: 'Bold Italic',

               underline: false

          }

     }

];

// Then use the above collection to filter the search

for (var i = 0, l = mapper.length; i < l; i += 1) {

     app.findTextPreferences = app.changeTextPreferences = null;

    

     for (var prop in mapper.props) {

          if (app.findTextPreferences.hasOwnProperty(prop)) {

               app.findTextPreferences[prop] = mapper.props[prop];

          }

     }

     app.changeTextPreferences.appliedCharacterStyle = mapper.charStyle;

     app.documents.item(0).changeText();

}

Legend
September 10, 2014

Try this,

//for bold underline formatting

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.fontStyle = "Bold"

app.findTextPreferences.underline=true;

app.changeTextPreferences.appliedCharacterStyle = "boldunderline";

app.documents.item(0).changeText();

app.findTextPreferences = app.changeTextPreferences = null;

Your first code is correct, just do some minor changes

Vandy