Copy link to clipboard
Copied
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
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Hi @Anantha Prabu G, thanks for the script! 🙂
Is it possible to adapt it, so that it works with all stories in the document?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Example document - one spread from 4x page document:
This is text structure of this document:
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.
Copy link to clipboard
Copied
Just for the record - the above can be done on Object Styles - and will be possible on Table / Cell Styles as well.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
This works also if your selection contains different sizes. Each changes proportionally.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 leading? OR maybe we could decrease it 2 points?
Thanks in advance for your help!
Rogerio
Copy link to clipboard
Copied
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 leading? OR 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;
Copy link to clipboard
Copied
Hi @Rogerio5C09, can you share an .indd demo document that shows this error?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi @Robert at ID-Tasker, thanks for checking!
Could you please specify where "()" are missing in the script?
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you so much! You're the best! 🙂
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more