17 Replies Latest reply on Aug 12, 2017 12:25 AM by Oriup

    Font size script

    B0b_The_Bui1der Level 1

      Hi, i was hoping it was possible to create a script to reduce all fonts in a given document down a point size (example: a heading at 16pt and a paragraph text at 12pt would then become 15pt and 11pt respectivly). I ask because I have a document and paragraph styles have not been used!! So is this possible and if so could anyone help with coming up with a relevant script? It also has to be able to work within tables!

       

      Many Thanks

       

      Rob

        • 1. Re: Font size script
          Fred Goldman Level 3

          If all the text is in one story this can be done without a script. Press Ctrl+Enter for quick apply and then type decrease and choose decrease font size (there is a keyboard shortcut for this, I just don't remember it). You can adjust how much it decreases by going to Edit-Prefernces-Units and  Increments.

          • 2. Re: Font size script
            Vainer.g Level 1

            You can use the InDesign built-in SEARCH AND REPLACE command. It allow you to search any fonts and size, and replace with tour new settings.

            1 person found this helpful
            • 3. Re: Font size script
              B0b_The_Bui1der Level 1

              Thanks giys, to answer the first question, no, the document is split up into various stories and tabular data so the quick search function will not do here.

               

              I will try the SEARCH AND REPLACE, although is there not a way a script could be created for the initial question, i.e regardless of the particular font used reducing ALL fonts in that document by 1pt etc. I had seen a script to do such a thing but that was reducing all document font's by a percentage which is not practical.

               

              Again thanks for your help so far, much appreciated

              • 4. Re: Font size script
                Tom Usrey Level 3

                This may or may not help (it's not my script). Go to this web page:

                 

                http://www.adobe.com/cfusion/exchange/index.cfm?event=authorExtensions&authorid=83085907

                 

                Download the "Resize selected text" script. It only works on selected text (you can either select the text itself or the text frame).

                1 person found this helpful
                • 5. Re: Font size script
                  B0b_The_Bui1der Level 1

                  Cheers Tom, thats more on the lines of what I'm after.

                   

                  I'm still wondering whether its possible to run a script to reduce all font size and leading size by 1pt etc, in a document which has numerous stories and tabular data etc?

                   

                  Rob

                  • 6. Re: Font size script
                    B0b_The_Bui1der Level 1

                    Is there anyway to adjust the following script so that I don't have to select the text before adjusting the size, i.e. once the script is activated it'l ask what size you want to adjust the text too in the whole document. This way I can adust the font sizes by 0.5pt in the whole document without selecting each and every story and tables.

                     

                    var the_document = app.documents.item(0);
                    var the_selection = app.selection[0];

                     

                    var the_dialog = app.dialogs.add({name:"Resize selected text"});
                    with(the_dialog.dialogColumns.add()){
                        with(dialogRows.add()){
                            staticTexts.add({staticLabel:"Resize the selected text by"});
                            var increase_by = measurementEditboxes.add({editUnits:MeasurementUnits.POINTS, editValue:0});
                        }
                    }
                    the_dialog.show();

                     

                    counter = 0;
                    do {
                        var current_character = the_selection.characters.item(counter);
                       
                        current_character.pointSize = current_character.pointSize + increase_by.editValue;
                        counter++;
                    } while (counter < the_selection.characters.length);

                     

                    alert("Done!");

                    • 7. Re: Font size script
                      Larry G. Schneider Adobe Community Professional & MVP

                      You might try

                       

                      var the_selection = app.textFrames.everyItem()

                      • 8. Re: Font size script
                        Mi_D Level 3

                        HI Rob

                        Try below code

                        add ur style name and point size

                         

                         

                        HI

                        var myDoc = app.activeDocument;

                        var myStyleNameList = new Array;

                        for(var a=0;a<myDoc.allParagraphStyles.length;a++){

                        if(app.activeDocument.paragraphStyles.item(a).name != "[No paragraph style]")

                             {

                             myStyleNameList.push(app.activeDocument.paragraphStyles.item(a).name);

                             }

                                  if (app.activeDocument.paragraphStyles.item(a).name =="a")

                                       {

                                       myDoc.paragraphStyles[a].pointSize = 15;

                         

                             }

                        }

                        MI_D

                         

                        • 9. Re: Font size script
                          B0b_The_Bui1der Level 1

                          Hi Larry,

                           

                          This did not seem to work, it returned the error:

                           

                          Capture.PNG

                          • 10. Re: Font size script
                            B0b_The_Bui1der Level 1

                            Hi Mi_D,

                             

                            Thanks for your script, however the indesign document I'm going to be working on will not have styles applied to it, thus i cannot add a style name to the script

                             

                            Do you have any other suggestions?

                            • 11. Re: Font size script
                              B0b_The_Bui1der Level 1

                              Just found this script on the adobe site which does the job.

                               

                              var myDocument = app.documents.item(0);
                              //Clear the find/change preferences.
                              app.findTextPreferences = NothingEnum.nothing;
                              app.changeTextPreferences = NothingEnum.nothing;
                              //Set the find options.
                              app.findChangeTextOptions.caseSensitive = false;
                              app.findChangeTextOptions.includeFootnotes = false;
                              app.findChangeTextOptions.includeHiddenLayers = false;
                              app.findChangeTextOptions.includeLockedLayersForFind = false;
                              app.findChangeTextOptions.includeLockedStoriesForFind = false;
                              app.findChangeTextOptions.includeMasterPages = false;
                              app.findChangeTextOptions.wholeWord = false;
                              //Search the document for the 12 point text and change it to 11 point text.
                              app.findTextPreferences.pointSize = 12;
                              app.changeTextPreferences.pointSize = 11;
                              myDocument.changeText();
                              //Clear the find/change preferences after the search.
                              app.findTextPreferences = NothingEnum.nothing;
                              app.changeTextPreferences = NothingEnum.nothing;

                               

                              However it means i have to enter in the text values from within the script (highlighted above). Could an alert window be used so that when i run the script i can enter the findTextPreferences.pointSize (eg. 10 pt) and then enter the changeTextPreferences.pointSize (eg. 9 pt) whilst the script has been activated, here's my example of the pop up window i'm trying to explain (excuse my photoshop skills!):

                               

                              Capture.jpg

                               

                              Or an even better script, would be regardless of the current text pt size (whether it be 12pt 14pt or 8pt) and reduce all txt sizes by a certain pt size....Its just so a user can literally click a and change all text sizes by a pt size at the click of a button.

                               

                              Hope im getting my point across, other than that i'll just use the find and change.

                              • 12. Re: Font size script
                                Haakenlid Level 3

                                This will change the point size and leading of every textRange in every story and table in the active document by -0.5 points.

                                 

                                var changePointSize = -0.5;
                                var changeLeading = -0.5;
                                var myTexts = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements();
                                myTexts = myTexts.concat(app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().textStyleRanges.everyItem().getElements());
                                var newLeading, newPointSize;
                                for (var n=myTexts.length-1; n>=0; n--){
                                     newPointSize = myTexts[n].pointSize+changePointSize;
                                     newLeading = myTexts[n].leading+changeLeading;
                                     myTexts[n].pointSize = (newPointSize>0)? newPointSize: myTexts[n].pointSize;
                                     myTexts[n].leading = (newLeading>0&&myTexts[n].leading!=Leading.AUTO)? newLeading: myTexts[n].leading;
                                }
                                
                                • 13. Re: Font size script
                                  Larry G. Schneider Adobe Community Professional & MVP

                                  I forgot to include the document. The app doesn't have text frames but the document does.

                                  • 14. Re: Font size script
                                    Oriup Level 1

                                    I have edited Haakenlid script.

                                     

                                    My script change point size in all Paragraph style.

                                     

                                    Here is my version:

                                     

                                    var changePointSize = 1;  
                                    var changeLeading = 2;  
                                    var myPStyle = app.activeDocument.allParagraphStyles;  
                                    var newLeading, newPointSize;  
                                    for (var i=1; i<myPStyle.length; i++){  
                                         newPointSize = myPStyle[i].pointSize+changePointSize;  
                                         newLeading = myPStyle[i].leading+changeLeading;  
                                         myPStyle[i].pointSize = (newPointSize>0)? newPointSize: myPStyle[i].pointSize;  
                                         myPStyle[i].leading = (newLeading>0&&myPStyle[i].leading!=Leading.AUTO)? newLeading: myPStyle[i].leading;  
                                    }
                                    

                                     

                                    Sumit

                                    1 person found this helpful
                                    • 15. Re: Font size script
                                      funkturmmitte Level 1

                                      The Script Haakenlid wrote works fine for me - as long as there are tables in the document.

                                      Can someone point me to a way to use this script also with documents with may not contain tables?

                                      The approach from Oriup is also nice, as my scripting knowledge increase i will try to cobine both of them so that the paragraph formats match the actual changes (if the text isnt modified).

                                      • 16. Re: Font size script
                                        Laubender Adobe Community Professional & MVP

                                        Hi,

                                        one could do several things:

                                        1. Add a single table to the document before running the script. :-)

                                        2. A quick fix of the script with a try/catch do nothing of line 4:

                                         

                                        var changePointSize = -0.5; 
                                        var changeLeading = -0.5; 
                                        var myTexts = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements();
                                        try{
                                        myTexts = myTexts.concat(app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().textStyleRanges.everyItem().getElements());
                                        }catch(e){};
                                        var newLeading, newPointSize; 
                                        for (var n=myTexts.length-1; n>=0; n--){ 
                                            newPointSize = myTexts[n].pointSize+changePointSize; 
                                            newLeading = myTexts[n].leading+changeLeading; 
                                            myTexts[n].pointSize = (newPointSize>0)? newPointSize: myTexts[n].pointSize; 
                                            myTexts[n].leading = (newLeading>0&&myTexts[n].leading!=Leading.AUTO)? newLeading: myTexts[n].leading; 
                                        }
                                        

                                         

                                        BTW: The script would not catch

                                        1. Text in tables that are nested in table cells.

                                        2. Text in footnotes

                                         

                                        Regards,
                                        Uwe

                                        1 person found this helpful
                                        • 17. Re: Font size script
                                          Oriup Level 1

                                          Hello Bob,

                                           

                                          Please use below code for the same.

                                           

                                          function show_window () {
                                            w = new Window ("dialog", "Text Resize");
                                            w.orientation = "row";
                                            w.alignChildren = "top";
                                            g1 = w.add("group");
                                            p = g1.add("panel");
                                            g2 = p.add("group");
                                            g2.add("statictext", [0,0,100,25], "Current pt size:");
                                            var find = g2.add("edittext {text: '12', characters: 8, justify: 'center'}")
                                            find.active = true;
                                            g2.add("statictext", undefined, "pt");
                                            g3 = p.add("group");
                                            g3.add("statictext", [0,0,100,25], "Change to:");
                                            var change  = g3.add("edittext {text: '11', characters: 8, justify: 'center'}")
                                            g3.add("statictext", undefined, "pt");
                                            g4 = w.add("group");
                                            g4.orientation = "column";
                                            g4.add("button", [0,0,85,25], "OK")
                                            g4.add("button", [0,0,85,25], "Cancel")
                                            if(w.show() == true){
                                            find_change (find.text, change.text);
                                            }
                                          }
                                          function find_change (find, change) {
                                            app.findGrepPreferences = app.changeGrepPreferences = null;
                                            app.findGrepPreferences.pointSize = find;
                                            app.changeGrepPreferences.pointSize = change;
                                            doc.changeGrep(true);
                                            app.findGrepPreferences = app.changeGrepPreferences = null;
                                          }
                                          if(app.documents.length>0){
                                            var doc = app.activeDocument;
                                            show_window ()
                                          }else{
                                            alert("Please open your document.");
                                            exit(0);
                                          }
                                          

                                           

                                           

                                          Sumit