Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

Decrease font size of all stories by 1 or 2 points

Contributor ,
Mar 21, 2024 Mar 21, 2024

Hi everyone,

I was wondering if anyone knows a script that decreases the font size of all stories by 1 or 2 points? I have lots of translated documents and the content is no longer fitting on the pages, so I could use a script 🙂

Thanks in advance for the help!
Rogerio

TOPICS
Scripting
3.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 22, 2024 Mar 22, 2024

Hi @Rogerio5C09, how about this script? It aims to quite literally reduce the point size of all text and doesn't care about Paragraph or Character Styles. I would imagine that, after running script, you might go through and use the "Redefine Style" command for your main styles.

- Mark

 

/**
 * Reduce point size of all text in document by 1.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/decrease-font-size-of-all-stories-by-1-or-2-points/m-p/14506004
 */
functio
...
Translate
Community Expert ,
Apr 18, 2024 Apr 18, 2024

Hi @Rogerio5C09, I don't have a script to do this. There is a discussion, including some code here. They discuss the issues related to this approach. Normally I would use the re-define style manually. The reason is that I would want only redefine my base style(s), not *every* style.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 07, 2024 Jun 07, 2024

Hi @m1b, almost 2 months later... I'm here again hahah. So, I have done some research and found the codes - I already merged them with your script (see below). For docs that contain manual overrides it's working just fine, but in case of no overrides found, the script keeps lopping and nothing happens. Could you please have a look? See attached an indd for testing. Thanks in advance, Rogerio.

 

var doc  = app.activeDocument;

      // search for overrides on paragraphs and characters
      // turn on Style Override Highlighter for visibility
      doc.textPreferences.enableStylePreviewMode = true;

for (s = 0; s < doc.stories.length; s++) {          
    var myStory = doc.stories[s]; 
     for (p = 0; p < myStory.characters.length; p++) { 
        var myCharacter = myStory.characters[p];
    for (p = 0; p < myStory.paragraphs.length; p++) { 
        var myParagraph = myStory.paragraphs[p];
        if(myCharacter.styleOverridden == true){
        if(myParagraph.styleOverridden == true){
            alert("This document contains manual overrides on text. Styles will not be redefined to preserve formatting.");
         
        // turn off Style Override Highlighter
        doc.textPreferences.enableStylePreviewMode = false;  
            
function main() {

    // adjust this function to suit your needs
    function myTextAdjuster(text) {
        
        if (text.pointSize <= 6)
            return;

        // reduce point size by 1 point
        text.pointSize -= 1;

        /* remove auto leading */
        if (Leading.AUTO === text.leading)
            text.leading = (text.pointSize * text.autoLeading / 100);

        /* reduce leading by 2 points - only do this if you already removed auto leading! */
        text.leading -= 2;

        /* turn autoleading on and set auto value to 120% */
        // text.leading = Leading.AUTO;
        // text.autoLeading = 120;

    };

    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

    var everyStory = app.activeDocument.stories.everyItem();

    var textStyleRanges = everyStory.paragraphs.everyItem().textStyleRanges.everyItem().getElements();

    try{
    if (everyStory.tables.everyItem().cells.everyItem().paragraphs.length)
         }catch(e){}
             try{
        textStyleRanges = textStyleRanges.concat(everyStory.tables.everyItem().cells.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements())
         }catch(e){}
             try{
    if (everyStory.tables.everyItem().cells.everyItem().paragraphs.length)
             }catch(e){}
                          try{
        textStyleRanges = textStyleRanges.concat(everyStory.footnotes.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements());
         }catch(e){}
    for (var i = textStyleRanges.length - 1; i >= 0; i--)
        myTextAdjuster(textStyleRanges[i]);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Reduce Document Text Sizes');

        // redefine styles if no overrides were found in the document
        if(myCharacter.styleOverridden == true){
        if(myParagraph.styleOverridden == true){
        exit();
        }
    }

for (s = 0; s < app.documents[0].stories.length; s++) {          
    var myStory = app.activeDocument.stories[s]; 
    
    // loop through each paragraph style in the document
    for (var i = 0; i < myStory.paragraphs.length; i++) {
        var para = myStory.paragraphs[i];
        var paraStyle = para.appliedParagraphStyle;
        paraStyle.properties = para.properties;
    }
    }

for (s = 0; s < app.documents[0].stories.length; s++) {          
    var myStory = app.activeDocument.stories[s]; 
    
    // loop through each character style in the document
    for (var i = 0; i < myStory.characters.length; i++) {
        var chara = myStory.characters[i];
        var charStyle = chara.appliedCharacterStyle;
        charStyle.properties = chara.properties;
    }
    }

alert("Done!");

            exit();
        }
    }
}
}
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 07, 2024 Jun 07, 2024

@Rogerio5C09

 

The first part - where you loop through all characters - you should change it to loop through TextStyleRanges.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 13, 2024 Jun 13, 2024

Hi @Robert at ID-Tasker, thanks for checking! 🙂 I'm not sure if that's the issue because if you run the "loop through each paragraph/character style" codes as a separate script, it works just fine. Am I missing something on lines 69-74?

Rogerio5C09_0-1718308135500.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 13, 2024 Jun 13, 2024
LATEST

@Rogerio5C09

 

I'm not JS guy, but those two ifs - don't make much sense?

 

They are not part of any loops? 

 

They are "out of context"? 

 

It looks like you are defining and executing main() inside a loops? 

 

And you are using the same "p" for looping through paragraphs and characters collections? 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines