2 Replies Latest reply on Sep 16, 2014 3:29 AM by mdegamo

    Formatting text into styles

    VeluVK

      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

        • 1. Re: Formatting text into styles
          Sajeev Sridharan Level 4

          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

          • 2. Re: Formatting text into styles
            mdegamo Level 1

            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[i].props) {
                      if (app.findTextPreferences.hasOwnProperty(prop)) {
                           app.findTextPreferences[prop] = mapper[i].props[prop];
                      }
                 }
            
                 app.changeTextPreferences.appliedCharacterStyle = mapper[i].charStyle;
                 app.documents.item(0).changeText();
            }