Skip to main content
Participating Frequently
April 22, 2019
Question

Change font size dynamically based on character count

  • April 22, 2019
  • 2 replies
  • 3512 views

Context: I have very basic experience with JavaScript. I mainly know HTML/CSS well.

Let's say I want to fill 1,000 pages with 1,000 phrases. One phrase per page, and the text has to fill the maximum amount of space in the page.

So I think I would need something like this: If "Hello there" is 60pt to fill the page, but the next page contains "How are you?" dynamically change the font size to fit the page (like 40pt). Am I on the right track or should I do something else?

I understand this may have something to do with strings and character counts. I have found some clues in JavaScript but also need help changing some of the language to work in InDesign.

jquery - Change Font Size dynamically based on Character count - Stack Overflow

jquery - Auto-size dynamic text to fill fixed size container - Stack Overflow

This topic has been closed for replies.

2 replies

Peter Kahrel
Community Expert
Community Expert
April 23, 2019

Character count is not a useful way to fit text in a frame. You can change the type size in small steps until the text fits the frame. Or better yet, check Marc Autret's site, he had a function (which I think he also showed in this forum), which uses a more sophisticated method to fit text to a frame. I don't have a link to that specific function -- Marc's site is at www.indiscripts.com.

P.

Community Expert
April 23, 2019

Hi Peter,

I think this is the article:

Indiscripts :: On Dichotomic Divide-and-Conquer Algorithms

Regards,
Uwe

Peter Kahrel
Community Expert
Community Expert
April 24, 2019

Yes, Uw, that's the one. Thanks for posting the link.

P.

Participant
April 23, 2019

In looking for a script to dynamically change text color, I found this:

Fun With Text Fitting in InDesign | in-tools.com

It's a link to a script and directions to fit text within a given frame size (in your example, the frame size could be the whole page).