Skip to main content
November 26, 2010
Answered

Font size script

  • November 26, 2010
  • 8 replies
  • 18020 views

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

This topic has been closed for replies.
Correct answer

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.pointSize+changePointSize;
     newLeading = myTexts.leading+changeLeading;
     myTexts.pointSize = (newPointSize>0)? newPointSize: myTexts.pointSize;
     myTexts.leading = (newLeading>0&&myTexts.leading!=Leading.AUTO)? newLeading: myTexts.leading;
}

8 replies

SumitKumar
Inspiring
November 18, 2016

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.pointSize+changePointSize; 

     newLeading = myPStyle.leading+changeLeading; 

     myPStyle.pointSize = (newPointSize>0)? newPointSize: myPStyle.pointSize; 

     myPStyle.leading = (newLeading>0&&myPStyle.leading!=Leading.AUTO)? newLeading: myPStyle.leading; 

}

Sumit

-Sumit
Correct answer
December 16, 2010

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.pointSize+changePointSize;
     newLeading = myTexts.leading+changeLeading;
     myTexts.pointSize = (newPointSize>0)? newPointSize: myTexts.pointSize;
     myTexts.leading = (newLeading>0&&myTexts.leading!=Leading.AUTO)? newLeading: myTexts.leading;
}

Known Participant
February 15, 2017

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).

Community Expert
February 16, 2017

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.pointSize+changePointSize;

    newLeading = myTexts.leading+changeLeading;

    myTexts.pointSize = (newPointSize>0)? newPointSize: myTexts.pointSize;

    myTexts.leading = (newLeading>0&&myTexts.leading!=Leading.AUTO)? newLeading: myTexts.leading;

}

BTW: The script would not catch

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

2. Text in footnotes

Regards,
Uwe

December 15, 2010

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!):

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.

SumitKumar
Inspiring
August 12, 2017

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

-Sumit
Inspiring
December 15, 2010

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.pointSize = 15;

     }

}

December 1, 2010

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).

December 2, 2010

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

New Participant
November 27, 2010

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.

November 28, 2010

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

Inspiring
November 26, 2010

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.