11 Replies Latest reply on Aug 18, 2016 2:54 AM by leenh61786917

    Paragraph style, first line bold

    leenh61786917 Level 1

      Hi all,

      I am trying to give a column in a table a paragraphstyle in which the first line is bold and the rest of the cell isn't, like this:

       

      ---------------------------------------------------------------------------------

      Column 2 cell 3

      Company name
      Adress

      Adress

       

      Column 2 cell 4

      Company name
      Adress

      Adress

      ---------------------------------------------------------------------------------

       

      I don't know if this is even possible but it would be a great help.

       

      I do apply the paragraph like this to the second column:

      ---------------------------------------------------------------------------------

      myTable.columns[1].cells.everyItem().texts[0].applyParagraphStyle(contentText);

      ---------------------------------------------------------------------------------

       

      The following is the contentText paragraph:

      ---------------------------------------------------------------------------------

      var contentText = myDocument.paragraphStyles.item("contentText");

          try

              {

                  var contentTextName = contentText.name;

              }

          catch (myError)

              {

                  contentText = myDocument.paragraphStyles.add({name:"contentText"});

              }

       

      contentText.appliedFont = "Arial";

      contentText.fontStyle = "Regular";

      contentText.pointSize = 10;

      contentText.spaceAfter = 10;

      contentText.spaceBefore = 10;

      contentText.fillColor = myDocument.colors.item("Black");

      ---------------------------------------------------------------------------------

       

      Is there a way to only let the first line be bold?

       

      Thanks in advance,

       

      Greetings

        • 1. Re: Paragraph style, first line bold
          Peter Spier Most Valuable Participant (Moderator)

          In the paragraph style definition set a nested Line Style.

          1 person found this helpful
          • 2. Re: Paragraph style, first line bold
            Willi Adelberger Most Valuable Participant

            You could do it in the nested style section of the paragraph style with line styles.

            But I would make different paragraph styles, each line its own, with next paragraph style defined and applied with the next style.

            1 person found this helpful
            • 3. Re: Paragraph style, first line bold
              leenh61786917 Level 1

              Thanks for the reply both. The problem for me is I can't find examples/information about nested styles and applying multiple paragraphs within one cell when it comes to scripting..

               

              I find things like this: Create and use nested styles in InDesign | Adobe InDesign CC tutorials

              Which are what I want to do, or with paragraphs inside of the cell, but I can't find any code about it...

               

              I have the information separated, like one variable for the company name and the other for the adress. I just need to know how to make 2 paragraphs within one cell so I can put the information in those paragraphs..

              • 4. Re: Paragraph style, first line bold
                Steve Werner Adobe Community Professional & MVP

                Ask in the InDesign Scripting forum:

                 

                InDesign Scripting

                • 6. Re: Paragraph style, first line bold
                  Laubender Adobe Community Professional & MVP

                  Hi,

                  you can work with a line style for your paragraph style, if your lines of text are not separated with paragraph signs like in the right example shown here:

                   

                  NestedLineStyle-PossibleWithExampleOnTheRightSide.png

                  If your text is composed like the left example using paragraph signs, you need a separate paragraph style for the first paragraph with Arial Bold.

                  As Willi Adelberger already pointed out.

                   

                  Example for adding a nested line style:

                   

                  var doc = app.documents[0];
                  
                  // Your paragraph style name that later should contain a line style:
                  var paraStyleName = "contentText";
                  // For defining a line style we need a character style:
                  var charStyleName = "FirstLineBold";
                  // All properties for the paragraph style:
                  var paraStyleProperties =
                  {
                      name : paraStyleName ,
                      appliedFont : "Arial" ,
                      fontStyle : "Regular",
                      pointSize : "10 pt",
                      spaceAfter : "10 pt",
                      spaceBefore : "10 pt",
                      fillColor : "Black"
                  };
                  // All properties for the character style we need for the line style:
                  var charStyleProperties =
                  {
                      name : charStyleName ,
                      fontStyle : "Bold"
                  }
                  
                  // Check, if the needed styles are there:
                  
                  // The paragraph style.
                  // using IS NOT VALID is recommended
                  if(!doc.paragraphStyles.itemByName(paraStyleName).isValid)
                  {
                      var paraStyle = doc.paragraphStyles.add(paraStyleProperties);
                  }
                  else
                  {
                      var paraStyle = doc.paragraphStyles.itemByName(paraStyleName);
                      paraStyle.properties = paraStyleProperties;
                  };
                  
                  // The character style.
                  // using IS NOT VALID is recommended
                  if(!doc.characterStyles.itemByName(charStyleName).isValid)
                  {
                      var charStyle = doc.characterStyles.add(charStyleProperties);
                  }
                  else
                  {
                      var charStyle = doc.characterStyles.itemByName(charStyleName);
                      charStyle.properties = charStyleProperties;
                  }
                  
                  // At this point we have a valid paragraph style and a valid character style.
                  // Now let's add a line style.
                  
                  /*
                      Note and warning:
                      In case the paragraph style already has one or several line styles we
                      have to either remove them to get our new line style at "pole position",
                      because there is no move() method to bring a new line style up in the stack of line styles.
                      
                      Or we have to redefine the first line style. Which is done below.
                      
                      About removing line styles:
                      Tested and is not working with CS6. Could be a bug.
                      paraStyle.nestedLineStyles.everyItem().remove()
                      So I think it is best to loop through and remove them one by one.
                  
                  */
                  
                  // Redefining the first line style if there is already one.
                  // Else add a new one.
                  
                  // Note: Using the properties-property is not working here:
                  
                  if(paraStyle.nestedLineStyles.count()>0)
                  {
                      paraStyle.nestedLineStyles[0].appliedCharacterStyle = charStyle;
                      paraStyle.nestedLineStyles[0].lineCount = 1;
                  }
                  else
                  {
                      paraStyle.nestedLineStyles.add({appliedCharacterStyle : charStyle , lineCount : 1});
                  }
                  

                   

                  For DOM documentation see the following sources:

                  Jongware:

                  Indesign JavaScript Help

                  Gregor Fellenz:

                  InDesign ExtendScript API (8.0)

                  InDesign ExtendScript API (10.0)

                  InDesign ExtendScript API (11.0)

                   

                  Regards,
                  Uwe

                  • 7. Re: Paragraph style, first line bold
                    Obi-wan Kenobi Adobe Community Professional

                    Hi,

                     

                    If i've understood well:

                     

                    Capture d’écran 2016-08-18 à 10.13.49.png

                    Capture d’écran 2016-08-18 à 10.14.07.png

                     

                    Of course, that will treat all the tables in the doc!

                     

                    app.activeDocument.stories.everyItem().tables.everyItem().columns[1].cells.everyItem().texts.everyItem().appliedParagraphStyle = "contentText";
                    app.activeDocument.stories.everyItem().tables.everyItem().columns[1].cells.everyItem().texts.everyItem().lines[0].appliedCharacterStyle = "FirstLineBold";
                    

                     

                    (^/) 

                    • 8. Re: Paragraph style, first line bold
                      Laubender Adobe Community Professional & MVP

                      Hi Obi-wan,

                      that would work, but it will create "overrides" of the paragraph style with a character style.

                       

                      And your script is changing all cells of all tables instead of the first column of a particular table.
                      ( The OP's code is suggesting, that only texts of the cells of the first column should be changed. )


                      Your code is ok, if all characters of the the first line still fit in the first line.

                      And even if not, its the desired effect in this special case here where the first line is separated to the next line by either a paragraph sign or a forced line break.

                       

                      In every other case where a nested line style is more appropriate and should format text in a more automated way, e.g. if the text contents is changed later by a script, we have to do the formatting with a nested line style as demonstrated with my script above.

                       

                      As we can see from the properties the OP is giving with the paragraph style the value for distance below and above could be a hint, that the first line of text is separated to the next line with a paragraph sign. Though, I could be wrong here. And for this kind of formatting it would be good to use a separate paragraph style, I think.

                       

                      Also no problem at all.

                      But let's see what the OP is thinking…

                       

                      Regards,
                      Uwe

                      • 9. Re: Paragraph style, first line bold
                        Obi-wan Kenobi Adobe Community Professional

                        Uwe,

                         

                        Answering, I was really more interested by your (eventual) comments!

                        I learn a lot studying how the [JS] masters think and write code lines!  Thanks! 

                         

                        (^/)

                        • 10. Re: Paragraph style, first line bold
                          Obi-wan Kenobi Adobe Community Professional

                          … If the op "clicks" in a table [just inserts the cursor in it]:

                           

                          app.selection[0].parent.parent.columns[1].cells.everyItem().texts.everyItem().appliedParagraphStyle = "contentText";
                          app.selection[0].parent.parent.columns[1].cells.everyItem().texts.everyItem().lines[0].appliedCharacterStyle = "FirstLineBold";
                          

                           

                           

                          (^/) 

                          • 11. Re: Paragraph style, first line bold
                            leenh61786917 Level 1

                            Thanks both for your answers, both great, but since I needed one column/cell I used the script of Laubender and it works like a charm. Also the validation of paragraphs being there etc is very nice. Thanks both of you