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
LEGEND ,
Mar 21, 2024 Mar 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.

 

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 ,
Mar 22, 2024 Mar 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.

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
Engaged ,
Mar 21, 2024 Mar 21, 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);
    }
    }
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 ,
Mar 22, 2024 Mar 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?

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 ,
Mar 22, 2024 Mar 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.

 

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 ,
Mar 22, 2024 Mar 22, 2024

Hi @Robert at ID-Tasker, there are no Paragragh styles in the documents I'm working on, so I'm afraif this script won't work 😞

Can anyone have take a look on this old post by any chance? It might help.
https://community.adobe.com/t5/indesign-discussions/font-size-script/m-p/3113967

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 ,
Mar 22, 2024 Mar 22, 2024

@Rogerio5C09

 

Are you working on a PC or Mac? 

 

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 ,
Mar 22, 2024 Mar 22, 2024

@Rogerio5C09 

 

Example document - one spread from 4x page document:

RobertTkaczyk_1-1711148020656.png

 

This is text structure of this document:

RobertTkaczyk_2-1711148332432.png

Marked in red - is how info is sorted - Font + PointSize.

Green - types of the blocks of text.

Marked in Blue - IDs of two separate Stories.

 

1st step - would be to focus on TextStyleRanges by hiding "Paragraphs" - convert them to CharStyles - by Font + PointSize.

 

2nd step - show Paragraphs and hide TextStyleRanges - create & apply ParaStyles.

 

So local formatting - fixing your document(s) by converting to Char / ParaStyles - sorted.

 

 

Now few extras - marked in Blue - if you would include this column in the sort order - as 1st key - you can style each Story separately - so you can create different Char/ParaStyles for each individual Story - so, for example, you can have different styles for body text, different for texts in tables, footnotes, Anchored TextFrames, etc.

 

As per top part of the screenshot - I've added "only" Font and PointSize info - you can add any of the 400+ text properties...

 

Plus you can sort & filter by left / right pages, layers, etc.

 

And you could pretty much run this on a whole server full of INDD files.

 

But - it's PC only - so if you are on Mac - we could make some arrangements.

 

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 ,
Mar 22, 2024 Mar 22, 2024

Just for the record - the above can be done on Object Styles - and will be possible on Table / Cell Styles as well. 

 

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
Community Expert ,
Mar 22, 2024 Mar 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.

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
Community Beginner ,
Mar 22, 2024 Mar 22, 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;
}

 

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
Community Beginner ,
Mar 23, 2024 Mar 23, 2024

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

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
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
 */
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.

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 ,
Mar 26, 2024 Mar 26, 2024

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

Rogerio5C09_0-1711470138397.png

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

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 ,
Mar 26, 2024 Mar 26, 2024
quote

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

Rogerio5C09_0-1711470138397.png

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;

 

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
Community Expert ,
Mar 26, 2024 Mar 26, 2024

Hi @Rogerio5C09, can you share an .indd demo document that shows this error?

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 ,
Mar 26, 2024 Mar 26, 2024
quote

Hi @Rogerio5C09, can you share an .indd demo document that shows this error?


By @m1b

 

As per screenshot - error is because "()" are missing at the end of the line.

 

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 ,
Apr 02, 2024 Apr 02, 2024

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

Could you please specify where "()" are missing in the script?

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 ,
Apr 02, 2024 Apr 02, 2024
quote

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

Could you please specify where "()" are missing in the script?


By @Rogerio5C09

 

Looks like line 14 is incomplete in your code:

RobertTkaczyk_0-1712101444192.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
Community Expert ,
Apr 04, 2024 Apr 04, 2024

Hi @Rogerio5C09, sorry for delay. I made changes to the script to make it easier for you to see how to adjust the leading. I also put in some checks that may fix the error you were seeing. Let me know if it helps.

- 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 ,
Apr 11, 2024 Apr 11, 2024

Thank you so much! You're the best! 🙂

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 ,
Apr 12, 2024 Apr 12, 2024

Hi @m1b, the script worked just as expected. Thanks again! 🙂 I'm trying to figure out now a way to make it work on all stories, except for paragraphs with small font-size (equal or lower than 6 pt). Would it be possible by any chance?

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
Community Expert ,
Apr 12, 2024 Apr 12, 2024

Hi @Rogerio5C09, the simplest approach would be to add a check to the start of the `myTextAdjuster` function that bails out if the point size is too small:

// adjust this function to suit your needs
function myTextAdjuster(text) {

    if (text.pointSize <= 6)
        return;

    ...

 

However, this doesn't address your *exact* request, because it checks TextStyleRange objects, not Paragraph objects. This means that if a paragraph has 6pt text and 10pt text, the script will still change the 10pt to 9pt even though it won't change the 6pt to 5pt. Let me know if you meant actual paragraphs.

- 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 ,
Apr 17, 2024 Apr 17, 2024

Hey @m1b! Yes, that's what I meant, so it should be fine in this case. Thanks for that!

Regarding your previous comment about redefining Paragraph and Character styles, I agree with you. Would you have a script for that? I woudn't run it on docs that have manual overrides on text though, otherwise formatting can get messed up. So, maybe we could add an alert at the start of the script in case the document contains overrides? Then, it still reduces text font size, but leave styles as they are?

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