Copy link to clipboard
Copied
var doc = app.activeDocument;
var textFrames = doc.textFrames;
var numTextFrames = textFrames.length; for (var i = 0; i < numTextFrames; i++) { var tf = textFrames[i]; if (tf.kind == TextType.AREATEXT && tf.textPath.contents.length > 0 && tf.textPath.overflows) { alert("Overset text detected in text frame " + (i+1)); } }
can anyone here help me on this!
This returns error
or any other way to alert
Try this
var doc = app.activeDocument;
var textFrames = doc.textFrames;
var numTextFrames = textFrames.length;
for (var i = 0; i < numTextFrames; i++) {
var tf = textFrames[i];
if (tf.kind == TextType.AREATEXT &&
tf.contents.length > 0 &&
overflows(tf)) {
alert("Overset text detected in text frame " + (i + 1));
// tf.selected = true;
}
}
function overflows(tf) {
var lastLine = tf.lines[tf.lines.length - 1];
var textRange1 = lastLine.con
...
Copy link to clipboard
Copied
Sorry, I wanted to reply to @femkeblanco
Copy link to clipboard
Copied
My previous code has a flaw because if one paragraph does not fit in a line and is wrapped to next lines, lines will be added to the textFrame.lines without being any newline character in the original text. The solution is to first count characters of all lines as before; then removing every carriage return in the full text and counting the remaining charactes in it; then comparing two numbers.
Note that as far as I have tested, Illustrator uses carriage return (\r) to separate paragraphs. I use Illustrator on Windows 10. I used a regular expression to remove the carriage return characters.
Updated version of my code:
function is_text_overflow(text){
var char_count_lines = 0;
var text_without_cr = text.textRange.contents.replace(/\r/g,"");
for(var i = 0; i < text.lines.length; i++)
char_count_lines += text.lines[i].contents.length;
return text_without_cr.length != char_count_lines;
}