Skip to main content
dublove
Legend
April 10, 2026
Question

How to determine if the bottom of a text frame is a table rather than plain text?

  • April 10, 2026
  • 2 replies
  • 25 views

Hello, everyone.
I want to use ‘s.fit(FitOptions.FRAME_TO_CONTENT)’ to shrink the bottom of a text box, but I want to exclude cases where the bottom border is part of a table.
I'm not sure if there's a way to do this.
Thank you

 

    2 replies

    m1b
    Community Expert
    Community Expert
    April 11, 2026

    Hi ​@dublove, here is a little function that attempts what you ask. See what you think. If it works, just put the function in your code, not the whole script.

    — Mark

    /**
    * @file Text Frame Safe To Adjust.js
    *
    * Demo of first attempt at `isSafeToAdjustTextFrameHeight` function
    * Might need more work to handle different situations.
    *
    * @author m1b
    * @version 2026-04-11
    * @discussion https://community.adobe.com/questions-671/how-to-determine-if-the-bottom-of-a-text-frame-is-a-table-rather-than-plain-text-1557176
    */
    (function () {

    var doc = app.activeDocument;
    var items = doc.selection;
    var goodTextFrames = [];

    for (var i = 0; i < items.length; i++) {

    if (isSafeToAdjustTextFrameHeight(items[i]))
    goodTextFrames.push(items[i]);

    }

    alert('' + goodTextFrames.length + ' are safe to adjust.');

    /**
    * Returns true, when the text frame is deemed okay to adjust.
    * @param {TextFrame} tf - the text frame to analyze.
    * @returns {Boolean}
    */
    function isSafeToAdjustTextFrameHeight(tf) {
    return (
    // we only want text frames
    TextFrame === tf.constructor
    // if the textframe has no characters, it might be filled with a table's rows
    && tf.characters.lastItem().isValid
    // u0016 is a table
    && '\u0016' !== tf.characters.lastItem().contents
    );
    };

    })();

     

    So here is how you could test it. First select all the text frames on your example spread and run it. But to actually fit the frames, use it something like this:

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

    for (var i = 0; i < items.length; i++) {

    if (isSafeToAdjustTextFrameHeight(items[i]))
    items[i].fit(FitOptions.FRAME_TO_CONTENT);

    }

     

    dublove
    dubloveAuthor
    Legend
    April 11, 2026

    It doesn't seem to have recognized it.

    Maybe we should try a different approach, like in that other post.
    Can we use `Offset` to determine the position of the last table border in the current text box?

        var hs = t.parent.parentStory.insertionPoints[t.storyOffset.index];
    //the empty space below the table and the end of the text frame
    var g = t.parent.geometricBounds[2]-hs.baseline;
    //all of the table’s rows
    var r = t.rows.everyItem().getElements();
    //the starting horizontal position of the table’s first cell
    var si = r[0].cells[0].insertionPoints[0].horizontalOffset

    var doc = app.activeDocument;
    var items = doc.selection;
    var goodTextFrames = [];
    for (var i = 0; i < items.length; i++) {
        if (isSafeToAdjustTextFrameHeight(items[i]))
            goodTextFrames.push(items[i]);
    }

    alert('' + goodTextFrames.length + ' are safe to adjust.');

    /**
     * Returns true, when the text frame is deemed okay to adjust.
     * @param {TextFrame} tf - the text frame to analyze.
     * @returns {Boolean}
     */

    function isSafeToAdjustTextFrameHeight(tf) {
        return (
            // we only want text frames
            //TextFrame === tf.constructor
            // if the textframe has no characters, it might be filled with a table's rows
            //&& tf.characters.lastItem().isValid
            // u0016 is a table
            '\u0016' !== tf.characters.lastItem().contents
        );
    };

     

    rob day
    Community Expert
    Community Expert
    April 10, 2026

    A table is treated a single character—it can break between text frames but only on a whole row.

     

    You can see the difference if you get the character counts of these 2 text frames

     

    var s = app.activeDocument.selection[0]
    alert("The selected text frame has " + s.characters.length + " characters")

     

     

    dublove
    dubloveAuthor
    Legend
    April 11, 2026

    This still does not confirm that the text box ends with a table at the bottom.