Skip to main content
Inspiring
March 21, 2024
Answered

Decrease font size of all stories by 1 or 2 points

  • March 21, 2024
  • 5 replies
  • 3403 views

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

This topic has been closed for replies.
Correct answer m1b

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
 */
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();

    if (
        everyStory.tables.length
        && everyStory.tables.everyItem().cells.everyItem().paragraphs.length
    )
        textStyleRanges = textStyleRanges.concat(everyStory.tables.everyItem().cells.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements())

    if (everyStory.footnotes.everyItem().paragraphs.length)
        textStyleRanges = textStyleRanges.concat(everyStory.footnotes.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements());

    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');

 

Edit 2024-03-23: for clarity of idea.

Edit 2024-04-05: to possibly help with OP's error by adding a couple of checks, and also structuring so easier to edit using `myTextAdjuster` function.

Edit 2024-04-15: fixed bug in one of the predicates. Then fixed bug in the other predicate.

5 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
March 23, 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
 */
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();

    if (
        everyStory.tables.length
        && everyStory.tables.everyItem().cells.everyItem().paragraphs.length
    )
        textStyleRanges = textStyleRanges.concat(everyStory.tables.everyItem().cells.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements())

    if (everyStory.footnotes.everyItem().paragraphs.length)
        textStyleRanges = textStyleRanges.concat(everyStory.footnotes.everyItem().paragraphs.everyItem().textStyleRanges.everyItem().getElements());

    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');

 

Edit 2024-03-23: for clarity of idea.

Edit 2024-04-05: to possibly help with OP's error by adding a couple of checks, and also structuring so easier to edit using `myTextAdjuster` function.

Edit 2024-04-15: fixed bug in one of the predicates. Then fixed bug in the other predicate.

Inspiring
March 26, 2024

Hi again @m1b! I just gave it a try, but I'm getting this error:

Also, I was wondering if it's possible to change leading as well? To AUTO leadingOR maybe we could decrease it 2 points?

Thanks in advance for your help!
Rogerio

Robert at ID-Tasker
Legend
March 26, 2024
quote

Hi again @m1b! I just gave it a try, but I'm getting this error:

Also, I was wondering if it's possible to change leading as well? To AUTO leadingOR maybe we could decrease it 2 points?

Thanks in advance for your help!
Rogerio


By @Rogerio5C09

 

Looks like you've copied it wrong?

 

 

And this line controls how much:

    var pointSizeAdjustment = -1;

 

Participant
March 23, 2024

This reduces the point size of the selection by a factor of .05 and rounds the number:

#targetengine "session";
TextContents = app.selection[0].characters;
TextLength = TextContents.length;
for (i=0; i<TextLength; i++)
{
Opera = TextContents[i].pointSize/1.05
PointSizeRound = Number(Opera.toFixed(1))
TextContents[i].pointSize = PointSizeRound;
}

Yould reduce by 1 point changing the operation:

#targetengine "session";
TextContents = app.selection[0].characters;
TextLength = TextContents.length;
for (i=0; i<TextLength; i++)
{
Opera = TextContents[i].pointSize-1
PointSizeRound = Number(Opera.toFixed(1))
TextContents[i].pointSize = PointSizeRound;
}

 

Participant
March 23, 2024

This works also if your selection contains different sizes. Each changes proportionally.

Willi Adelberger
Community Expert
Community Expert
March 22, 2024

I suppose that you use paragraph styles as never a work should be done without styles or with manual overrides, change the size in your PARAGRAPH Styles. That is the correct way.

Anantha Prabu G
Legend
March 22, 2024

@Rogerio5C09 

Sample script for reducing font size by one point for specific paragraph styles.

var doc = app.activeDocument;

// Define the paragraph styles you want to modify
var paragraphStyles = ["H1", "H2"];

// Loop through each paragraph style
for (var i = 0; i < paragraphStyles.length; i++) {
    var styleName = paragraphStyles[i];
    var style = doc.paragraphStyles.itemByName(styleName);
    
    // Reduce font size by one point
    if (style.isValid) {
        var currentPointSize = style.pointSize;
        style.pointSize = currentPointSize - 1;
        alert("Font size reduced by one point for paragraph style: " + styleName);
    }
    }
Design smarter, faster, and bolder with InDesign scripting.
Inspiring
March 22, 2024

Hi @Anantha Prabu G, thanks for the script! 🙂

Is it possible to adapt it, so that it works with all stories in the document?

Robert at ID-Tasker
Legend
March 22, 2024
quote

Hi @Anantha Prabu G, thanks for the script! 🙂

Is it possible to adapt it, so that it works with all stories in the document?


By @Rogerio5C09

 

If you've your text formatted using Paragraph Styles - it will work.

 

Robert at ID-Tasker
Legend
March 21, 2024

Do all Stories have exactly the same PointSize - or each one can have different PointSize?

 

And WHOLE Story have exactly the same PointSize - or parts of the text withing the Story can have different sizes?

 

First para.

Second para.

Third para.

 

Inspiring
March 22, 2024

Hi @Robert at ID-Tasker, thanks for checking! 

Each story can have different PointSize and yes, parts of the text withing the Story can have different sizes.