Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Special case? GeometricBounds positioning cannot be used when text boxes extend beyond bleed?

Guide ,
Aug 01, 2025 Aug 01, 2025
The object is just crossing the bleeding area, and it seems impossible to determine its position.
sel[j].parentPage;.marginPreferences.bottom;
will cause an error.
 
0011.png699.png
 var sel = app.documents[0].selection;
        var pp = sel[j].parentPage;
        var b = app.activeDocument.selection[j].geometricBounds;
        var sb = sel[0].visibleBounds;
        var bm = pp.marginPreferences.bottom;
 
if(sel[j].parentPage == null);
b[1]<0&&b[3>0]&&b[3]<cp[0];
 
All combinations have failed...
            if ((sel[j].parentPage == null && b[3] < 0) || ([1] < 0 && b[3] > 0 && b[3] < cp[0])) {
                app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                sel[j].geometricBounds = [b[0], 0 - 20, b[2], b[3] - b[1] + 20];
            }

            if ((sel[j].parentPage == null) && (b[1] > 0)) {
                app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                sel[j].geometricBounds = [b[0], 0 - 20, b[2], b[3] - b[1] - 20];
            }
TOPICS
Bug , How to , Scripting
475
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Aug 02, 2025 Aug 02, 2025

@dublove the challenge here—as Brian alluded—is that you are trying to get the page of an item that has no page. So we need to get the nearest page to the item. I've written a function to do that, and a little example script to show it.

- Mark

 

/**
 * @file Position Item On Nearest Page.js
 *
 * @author m1b
 * @version 2025-08-02
 * @discussion https://community.adobe.com/t5/indesign-discussions/special-case-geometricbounds-positioning-cannot-be-used-when-text-boxes-extend-beyond-bleed/m-p/1544
...
Translate
Community Expert , Aug 02, 2025 Aug 02, 2025

Hi @dublove all this talk of "jumping"... you must read what my example is trying to do. That first example always moves the item to the bottom left margins. It was just an example—you can code it to move where you want it.

 

For example, the following code ensures that the selected item is within the page margins, and it will move the item only the minimum distance required to achieve that. Again, remember these are just examples. You must adjust them the way you want.

 

By the way, I would avo

...
Translate
Community Expert , Sep 10, 2025 Sep 10, 2025

It only applies to situations outside the left page.

 

Hi @dublove , If you can’t get @m1b code to work try this—it gets the selection’s parent which is a spread and is not null. Note that a spread could have up to 10 pages, so this moves the object to the spread’s closest outside page:

 



var d = app.activeDocument;
//set the document’s ruler origin to spread and zero point to 0
d.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
d.zeroPoint = [0, 0];

//The first item in the selection
...
Translate
Community Expert ,
Aug 01, 2025 Aug 01, 2025

Yes, an object off the page will have an invalid parentPage. Gonna have to find another way to identify it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2025 Aug 01, 2025

Use a different reference point of the text frame, like the center.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 01, 2025 Aug 01, 2025

Can you give me a rough idea?
For example?

 if (b[1] < 0 && (b[1] +(b[3] - b[1]) / 2) > 0)
or
 if (b[1< 0 && (b[3- (b[3- b[1]) / 2> 0)
?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 02, 2025 Aug 02, 2025

@dublove the challenge here—as Brian alluded—is that you are trying to get the page of an item that has no page. So we need to get the nearest page to the item. I've written a function to do that, and a little example script to show it.

- Mark

 

/**
 * @file Position Item On Nearest Page.js
 *
 * @author m1b
 * @version 2025-08-02
 * @discussion https://community.adobe.com/t5/indesign-discussions/special-case-geometricbounds-positioning-cannot-be-used-when-text-boxes-extend-beyond-bleed/m-p/15440515
 */
function main() {

    var sel = app.activeDocument.selection[0];
    var pp = getNearestPage(sel);

    var pb = pp.bounds;
    var sb = sel.visibleBounds;
    var bm = pp.marginPreferences.bottom;
    var lm = pp.marginPreferences.left;

    // example: line up `sel` against the left and bottom margins of the page
    sel.move([pb[1] + lm, pb[2] - bm - (sb[2] - sb[0])]);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Do Script');

/**
 * Returns the nearest page to `item`.
 * @author m1b
 * @version 2025-08-02
 * @param {PageItem} item - the target item.
 * @returns {Page} - the nearest page to `item`.
 */
function getNearestPage(item) {

    var page = item.parentPage;
    var spread;

    while (!page) {

        spread = item.parent;

        if ('Page' === spread.constructor.name)
            page = spread;


        if ('Spread' === spread.constructor.name) {

            var index = findClosestBounds(
                item.visibleBounds,
                spread.pages.everyItem().bounds
            );

            page = spread.pages.item(index);

        }

    }

    return page;

};

/**
 * Returns the index of the bounds in `boundsArray` that is
 * closest to the target bounds. All bounds are in [T, L, B, R] format.
 * @param {Array} targetBounds - The target bounds [T, L, B, R].
 * @param {Array<bounds>} boundsArray - An array of bounds arrays.
 * @returns {Number} Index of the closest bounds in the array.
 */
function findClosestBounds(targetBounds, boundsArray) {

    var targetCenter = centerOfBounds(targetBounds);
    var minDist = Infinity;
    var closestIndex = -1;

    for (var i = 0, center, dx, dy, distSq; i < boundsArray.length; i++) {

        center = centerOfBounds(boundsArray[i]);
        dx = targetCenter[0] - center[0];
        dy = targetCenter[1] - center[1];
        distSq = dx * dx + dy * dy;

        if (distSq < minDist) {
            minDist = distSq;
            closestIndex = i;
        }

    }

    return closestIndex;

};

/** 
 * Returns the center of `bounds`;
 * @param {Array} bounds - The bounds [T, L, B, R].
 * @returns {Array<Number>} - [cx, cy].
 */
function centerOfBounds(bounds) {
    return [(bounds[1] + bounds[3]) / 2, (bounds[0] + bounds[2]) / 2];
};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 02, 2025 Aug 02, 2025

Hi @m1b .
Thank you very much.

Your script does indeed move the object into the layout.
However, the object is offset too far in the Y direction, The feeling of jumping is not good.

 

 

I thought of another simple and effective method, which is to scale down the image proportionally and then reset it to

sel[j].geometricBounds = [c[0], cp[0], c[0] + hnew, cp[0] + wnew,]


cp[0] and cp[0] + wnew always exist and are real values,
so simply translating them will work.

 

I will try my best to make sure that the object does not jump up and down, and it is best to deform it without moving the upper left corner.
But that's all for later.

 

Oh,my Great m1b, don't forget me.

headerRows = convertToRowType(headerRows, RowTypes.HEADER_ROW);

This is what keeps me awake at night.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 02, 2025 Aug 02, 2025

Hi @dublove all this talk of "jumping"... you must read what my example is trying to do. That first example always moves the item to the bottom left margins. It was just an example—you can code it to move where you want it.

 

For example, the following code ensures that the selected item is within the page margins, and it will move the item only the minimum distance required to achieve that. Again, remember these are just examples. You must adjust them the way you want.

 

By the way, I would avoid setting the geometricBounds as it can be messy. Better to use the .move and .resize methods, I think.

- Mark

 

/**
 * @file Position Item Within Nearest Page Margins.js
 *
 * @author m1b
 * @version 2025-08-02
 * @discussion https://community.adobe.com/t5/indesign-discussions/special-case-geometricbounds-positioning-cannot-be-used-when-text-boxes-extend-beyond-bleed/m-p/15440515
 */
function main() {

    var sel = app.activeDocument.selection[0];
    var pp = getNearestPage(sel);

    var pb = pp.bounds;
    var sb = sel.visibleBounds;
    var sw = sb[3] - sb[1];
    var sh = sb[2] - sb[0];

    // example: move `sel` so it is within the page margins
    var x = sb[1];
    var y = sb[0];

    if (sb[3] > pb[3] - pp.marginPreferences.right) {
        // the item is past the right side of the page
        x = pb[3] - pp.marginPreferences.right - sw;
    }
    if (sb[1] < pb[1] + pp.marginPreferences.left) {
        // the item is past the left side of the page
        x = pb[1] + pp.marginPreferences.left;
    }
    if (sb[2] > pb[2] - pp.marginPreferences.bottom) {
        // the item is past the bottom of the page
        y = pb[2] - pp.marginPreferences.bottom - sh;
    }
    if (sb[0] < pb[0] + pp.marginPreferences.top) {
        // the item is past the top of the page
        y = pb[0] + pp.marginPreferences.top;
    }

    sel.move([x, y]);

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Move Item Inside Page Margins');

/**
 * Returns the nearest page to `item`.
 * @author m1b
 * @version 2025-08-02
 * @param {PageItem} item - the target item.
 * @returns {Page} - the nearest page to `item`.
 */
function getNearestPage(item) {

    var page = item.parentPage;
    var spread;

    while (!page) {

        spread = item.parent;

        if ('Page' === spread.constructor.name)
            page = spread;


        if ('Spread' === spread.constructor.name) {

            var index = findClosestBounds(
                item.visibleBounds,
                spread.pages.everyItem().bounds
            );

            page = spread.pages.item(index);

        }

    }

    return page;

};

/**
 * Returns the index of the bounds in `boundsArray` that is
 * closest to the target bounds. All bounds are in [T, L, B, R] format.
 * @param {Array} targetBounds - The target bounds [T, L, B, R].
 * @param {Array<bounds>} boundsArray - An array of bounds arrays.
 * @returns {Number} Index of the closest bounds in the array.
 */
function findClosestBounds(targetBounds, boundsArray) {

    var targetCenter = centerOfBounds(targetBounds);
    var minDist = Infinity;
    var closestIndex = -1;

    for (var i = 0, center, dx, dy, distSq; i < boundsArray.length; i++) {

        center = centerOfBounds(boundsArray[i]);
        dx = targetCenter[0] - center[0];
        dy = targetCenter[1] - center[1];
        distSq = dx * dx + dy * dy;

        if (distSq < minDist) {
            minDist = distSq;
            closestIndex = i;
        }

    }

    return closestIndex;

};

/**
 * Returns the center of `bounds`;
 * @param {Array} bounds - The bounds [T, L, B, R].
 * @returns {Array<Number>} - [cx, cy].
 */
function centerOfBounds(bounds) {
    return [(bounds[1] + bounds[3]) / 2, (bounds[0] + bounds[2]) / 2];
};

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 02, 2025 Aug 02, 2025

It seems that the content on the right side of the right page will not be moved.

 

I'll change it when I have time.
At least I haven't found any major problems yet, and it would take me a whole day to do it.

 

I'll bookmark it for now. Thank you very much.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 02, 2025 Aug 02, 2025

Hi m1b. The method I mentioned for changing cp[0] doesn't work very well afterwards.

In your code,
the right page doesn't need to be moved.

I found another solution. This code will only be executed when a catch occurs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 02, 2025 Aug 02, 2025

Hi @m1b 

Is this possible?

Get the name of the paragraph style

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 08, 2025 Sep 08, 2025

@m1b 

moveInLeftLayout();
Does this only work for objects outside the left-page layout?
Is there no moveInRightLayout()?

When the object is positioned outside the right-hand page layout, the script appears to be ineffective.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2025 Sep 09, 2025

Hi @dublove I don't see the function moveInLeftLayout. What are you talking about?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 09, 2025 Sep 09, 2025

Hi @m1b 

Oh, sorry, I changed the function name.
It should be the one below: 

function main() {
    var sel = app.activeDocument.selection[0];
    var pp = getNearestPage(sel);

 It only applies to situations outside the left page.
The object may not apply when located at the following positions:
The right side of the right page when spanning pages,
The right side of a single page,
The right side of the first page,
The right side of the last page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2025 Sep 10, 2025

It only applies to situations outside the left page.

 

Hi @dublove , If you can’t get @m1b code to work try this—it gets the selection’s parent which is a spread and is not null. Note that a spread could have up to 10 pages, so this moves the object to the spread’s closest outside page:

 



var d = app.activeDocument;
//set the document’s ruler origin to spread and zero point to 0
d.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
d.zeroPoint = [0, 0];

//The first item in the selection
var sel = d.selection[0];

//make sure there is a selection that has bounds
if (sel == undefined || !sel.hasOwnProperty("geometricBounds")) {
	alert("No Text Frame Selected")
} else {
    //if the selection is not on a page move it
    if (sel.parentPage == null ) {
        var mp = movePBSel(sel)
        alert("Moved to page: " + mp.name)
    }
}

/**
* Move a pasteboard selection  
* @ param the selection to move 
* @ return the parent page after the move
*/

function movePBSel(s){
    //the selection’s parent is a spread even if it is off the page
    var pp = s.parent.pages

    //move to the nearest page’s top, left margin
    if (pp.length == 1) {
        s.move([ pp[0].marginPreferences.left, pp[0].marginPreferences.top ] );
    } else {
        //a selection on the pasteboard to the left or right of the spread
        if (s.geometricBounds[3] < 0) {
            s.move([pp[0].marginPreferences.left, pp[0].marginPreferences.top ]);
        } else {
            var px = pp[pp.length-1].bounds[1]
            s.move([ px+pp[0].marginPreferences.left , pp[0].marginPreferences.top ] );
        }
    }
    return s.parentPage
}

 

Selection on the pasteboard to the left of a sprread:

 

Screen Shot 1.png

Screen Shot 2.png

 

Selection on the pasteboard to the right of a sprread:

 

Screen Shot 3.png

Screen Shot 4.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 11, 2025 Sep 11, 2025

Hi @rob day 

Thank you very much, that's a good point.
I've already implemented it using a rather clumsy method. I don't plan to modify it for now.


I'll switch to yours when I have time.

I've broken it down into several different scenarios.

 if (pp.side == PageSideOptions.RIGHT_HAND) {

        // Right-to-right across pages, first page right-to-right
        if (sb[1] > pb[3]
            && sb[1] > 0
            && pp.documentOffset == 0
        ) {
            x = cp[cp.length - 1] + lm;
        }

        // Page 1 left-left
        if (sb[1] < 0 && pp.documentOffset == 0) {
            x = 0 + lm;
        }
.....

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2025 Sep 11, 2025

You have to be careful with the side property. Most of the time it would work, but a document could have facing pages unchecked and still have multi page spreads. In this case all the pages return as SINGLE_SIDED:

 

var p = app.activeDocument.pages[1]
alert("Page 2 Side is: " + p.side.toString())

 

Screen Shot 9.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 18, 2025 Sep 18, 2025
LATEST

@rob day 

How to modify horizontal shifting.
Left side shifts to cp[0], right side shifts to cp[cp.length-1].

dublove_0-1758205243993.jpeg

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines