Skip to main content
dublove
Legend
May 15, 2026
Answered

I'm looking for a script that converts text lines to text blocks and vice versa.

  • May 15, 2026
  • 2 replies
  • 59 views

Hi everyone.

It should automatically detect the current state.
Whether the current state is “text selection mode,” “cursor in text,” or “text selected.”
After running the script:
If the text is a line, convert it to a block.
If it is a block, convert it to a line.

Also, make sure to check “Automatically adjust text size in the area” in the preferences.

Thank you very much.

    Correct answer m1b

    Hi ​@dublove here are a couple of functions for converting between POINT-type and AREA-type text frames. Be prepared for a learning curve—Illustrator text frames, unfortunately, are not the same as Indesign’s. Illustrator’s scripting API for text objects is much less sophisticated and there are more strange quirks.

    But this is a start…

    — Mark

    /**
    * @file Convert Text Frame Type.js
    *
    * Demonstration of converting a text frame and
    * getting a reference to the converted text frame.
    *
    * @author m1b
    * @version 2026-05-17
    * @discussion https://community.adobe.com/questions-652/i-m-looking-for-a-script-that-converts-text-lines-to-text-blocks-and-vice-versa-1561735?tid=1561735
    */
    (function () {

    var doc = app.activeDocument;
    var items = doc.selection;

    for (var i = items.length - 1; i >= 0; i--) {

    var item = items[i];

    if (TextType.AREATEXT === item.kind)
    item = convertAreaTextToPointText(item);

    else if (TextType.POINTTEXT === item.kind)
    item = convertPointTextToAreaText(item);

    }

    })();

    /**
    * Converts an point-type text frame to a area-type text frame.
    * @author m1b
    * @version 2026-05-17
    * @param {TextFrame} item - an Illustrator Text Frame.
    * @returns {TextFrame}
    */
    function convertPointTextToAreaText(item) {

    if (TextType.POINTTEXT !== item.kind)
    return;

    var temp = item.duplicate();

    // convert
    temp.convertPointObjectToAreaObject();

    // get fresh reference to converted textFrame
    for (var i = 1; i < item.layer.textFrames.length; i++) {
    if (item.layer.textFrames[i].uuid == item.uuid) {
    var convertedItem = item.layer.textFrames[i - 1];
    item.remove();
    item = convertedItem;
    break;
    }
    }

    // remove trailing spaces
    while (' ' === item.characters[item.characters.length - 1].contents)
    item.characters[item.characters.length - 1].remove();

    return item;

    };

    /**
    * Converts an area-type text frame to a point-type text frame.
    * @author m1b
    * @version 2022-02-09
    * @param {TextFrame} item - an Illustrator Text Frame.
    * @returns {TextFrame}
    */
    function convertAreaTextToPointText(item) {

    if (TextType.AREATEXT !== item.kind)
    return;

    var temp = item.duplicate();

    // oversetText causes errors later
    discardOversetText(temp);

    // convert
    temp.convertAreaObjectToPointObject();

    // get fresh reference to converted textFrame
    for (var i = 1; i < item.layer.textFrames.length; i++) {
    if (item.layer.textFrames[i].uuid == item.uuid) {
    var convertedItem = item.layer.textFrames[i - 1];
    item.remove();
    item = convertedItem;
    break;
    }
    }

    // remove trailing spaces
    while (' ' === item.characters[item.characters.length - 1].contents)
    item.characters[item.characters.length - 1].remove();

    return item;

    };

    /**
    * Removes overset text from an Area type text frame.
    * @author m1b
    * @version 2022-02-09
    * @param {TextFrame} item - an Illustrator Text Frame.
    */
    function discardOversetText(item) {

    var lastVisibleChar = item.lines[item.lines.length - 1].characters[item.lines[item.lines.length - 1].characters.length - 1];
    var lastOffset = lastVisibleChar.characterOffset;

    for (var i = item.characters.length - 1; i >= lastOffset; i--)
    item.characters[i].remove();

    };

     

    2 replies

    m1b
    Community Expert
    m1bCommunity ExpertCorrect answer
    Community Expert
    May 16, 2026

    Hi ​@dublove here are a couple of functions for converting between POINT-type and AREA-type text frames. Be prepared for a learning curve—Illustrator text frames, unfortunately, are not the same as Indesign’s. Illustrator’s scripting API for text objects is much less sophisticated and there are more strange quirks.

    But this is a start…

    — Mark

    /**
    * @file Convert Text Frame Type.js
    *
    * Demonstration of converting a text frame and
    * getting a reference to the converted text frame.
    *
    * @author m1b
    * @version 2026-05-17
    * @discussion https://community.adobe.com/questions-652/i-m-looking-for-a-script-that-converts-text-lines-to-text-blocks-and-vice-versa-1561735?tid=1561735
    */
    (function () {

    var doc = app.activeDocument;
    var items = doc.selection;

    for (var i = items.length - 1; i >= 0; i--) {

    var item = items[i];

    if (TextType.AREATEXT === item.kind)
    item = convertAreaTextToPointText(item);

    else if (TextType.POINTTEXT === item.kind)
    item = convertPointTextToAreaText(item);

    }

    })();

    /**
    * Converts an point-type text frame to a area-type text frame.
    * @author m1b
    * @version 2026-05-17
    * @param {TextFrame} item - an Illustrator Text Frame.
    * @returns {TextFrame}
    */
    function convertPointTextToAreaText(item) {

    if (TextType.POINTTEXT !== item.kind)
    return;

    var temp = item.duplicate();

    // convert
    temp.convertPointObjectToAreaObject();

    // get fresh reference to converted textFrame
    for (var i = 1; i < item.layer.textFrames.length; i++) {
    if (item.layer.textFrames[i].uuid == item.uuid) {
    var convertedItem = item.layer.textFrames[i - 1];
    item.remove();
    item = convertedItem;
    break;
    }
    }

    // remove trailing spaces
    while (' ' === item.characters[item.characters.length - 1].contents)
    item.characters[item.characters.length - 1].remove();

    return item;

    };

    /**
    * Converts an area-type text frame to a point-type text frame.
    * @author m1b
    * @version 2022-02-09
    * @param {TextFrame} item - an Illustrator Text Frame.
    * @returns {TextFrame}
    */
    function convertAreaTextToPointText(item) {

    if (TextType.AREATEXT !== item.kind)
    return;

    var temp = item.duplicate();

    // oversetText causes errors later
    discardOversetText(temp);

    // convert
    temp.convertAreaObjectToPointObject();

    // get fresh reference to converted textFrame
    for (var i = 1; i < item.layer.textFrames.length; i++) {
    if (item.layer.textFrames[i].uuid == item.uuid) {
    var convertedItem = item.layer.textFrames[i - 1];
    item.remove();
    item = convertedItem;
    break;
    }
    }

    // remove trailing spaces
    while (' ' === item.characters[item.characters.length - 1].contents)
    item.characters[item.characters.length - 1].remove();

    return item;

    };

    /**
    * Removes overset text from an Area type text frame.
    * @author m1b
    * @version 2022-02-09
    * @param {TextFrame} item - an Illustrator Text Frame.
    */
    function discardOversetText(item) {

    var lastVisibleChar = item.lines[item.lines.length - 1].characters[item.lines[item.lines.length - 1].characters.length - 1];
    var lastOffset = lastVisibleChar.characterOffset;

    for (var i = item.characters.length - 1; i >= lastOffset; i--)
    item.characters[i].remove();

    };

     

    dublove
    dubloveAuthor
    Legend
    May 17, 2026

    Hi, ​@m1b 
    So you're here too.
    Can you add a feature to automatically adjust the text box while converting to regional text?

    Also, does Illustrator have a script reference manual?

    Thank you.

    m1b
    Community Expert
    Community Expert
    May 17, 2026

    Yes! I’m here too! :)

    Here are the docs I use for Illustrator.

    —Mark

    dublove
    dubloveAuthor
    Legend
    May 16, 2026

    I found this, but I'm not sure what's wrong with it—it doesn't do anything.
    This is for making the text box fit the text.
    There's no feature to convert point text to area text.

    /**
    * @name fit_frame_to_text
    *
    *@Original post
    https://community.adobe.com/questions-652/fit-frame-to-text-free-script-793627
    *
    * **/
    //var aDoc = app.activeDocument;
    //var aTF = aDoc.ss[0];
    //aTF.convertAreaObjectToPointObject();
    //aTF.convertPointObjectToAreaObject();

    var item = activeDocument.selection;
    for (var i = 0; i < item.length; i++) { // iterate over each item in AI's janky selection object

    fitFrame([item[i]]);
    }

    function fitFrame(s) { // s must be a TextFrameItem
    if (!(s instanceof TextFrame && s.kind == TextType.AREATEXT)) { // ignore point/path text
    return -1;
    }
    var limit = 0.2;
    var textPath = s.textPath;
    var textLength = s.contents.replace(/\s+$/, "").length; // get length of printable text (ignores trailing whitespace)
    if (textLength === 0) {
    textPath.height = 0; // text frame is empty so set to zero-height and return
    return 0;
    }
    var h = textPath.height;
    // if frame has no height, add some to get things started
    if (h < limit) {
    h = limit;
    textPath.height = h;
    }

    // overflow checker; this checks length of printable text to index of last visible character in frame
    var hasOverflow = function () {
    var lastLine = s.lines[s.lines.length - 1];
    if (lastLine === undefined) { // no lines are visible (frame is too small)
    return textLength > 0;
    }
    return textLength > (lastLine.characters[0].characterOffset + lastLine.length - 1);
    }
    // adjust text frame height using two-stage divide and conquer; crude, but works, and acceptably fast
    // find initial approximate min and max heights between which text overflow occurs
    var oh;
    if (hasOverflow()) {
    do {
    oh = h;
    h *= 1.5;
    textPath.height = h;
    } while (hasOverflow());
    } else {
    do {
    oh = h;
    h /= 1.5;
    textPath.height = h;
    } while (!hasOverflow());
    }
    // narrow the difference between min and max approximations till it falls within limit
    var d = oh - h;
    if (d < 0) { d = -d; }
    while (d > limit) {
    d /= 2;
    h += (hasOverflow() ? d : -d);
    textPath.height = h;
    }
    // if final reduction caused overflow, undo it
    if (hasOverflow()) {
    textPath.height = h + d;
    }
    return textPath.height;
    }