Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 87530

Re: How do I locate the longest line in an InDesign document?

$
0
0

Hi Duke;

 

The following is something quick and dirty that looks at the number of characters in a line only. This ignores what the others were saying in regards to 'physical space' which may include kerning, scaling, character widths etc, and it only looks at 1 text frame so you might have to expand on it if you want to do a whole document.

 

var myLines = app.activeDocument.textFrames.item(0).lines;
var myLongestLine = 0;
var myLongestLineGroup = "";
for (var i = 0; i < myLines.length; i++) {    if (myLines[i].characters.length === myLongestLine) {        myLongestLineGroup += "Line - " + i + "\u000D";        }    else if (myLines[i].characters.length > myLongestLine) {        myLongestLine = myLines[i].characters.length;        myLongestLineGroup = "Line - " + i + "\u000D";        }    }
$.write("The longest lines are: \u000D" + myLongestLineGroup + "With " + myLongestLine + " characters including white spaces and breaks.\u000D");


If you were after the physical space of a line then another couple of steps would be required. This can be problematic thought especially if the text is not forced to a fixed word, letter and glyph scaling as these paragraph style values can dramatically change the outcome (the default paragraph style has a 80% minimum word spacing by the way so it might cause variations in the result).

 

Brett


Viewing all articles
Browse latest Browse all 87530

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>