Last active
July 8, 2025 21:21
-
-
Save narthur/ab7ae5fcc6a723e8bf6f to your computer and use it in GitHub Desktop.
InDesign JSX User Script to Adjust Table Widths Relative to Frame Width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspiration: | |
// https://forums.adobe.com/message/2524327 | |
// http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap | |
var myDoc = app.activeDocument; | |
function getWidth(/*PageItem*/obj, /*bool*/visible) | |
// return the [width,height] of <obj> | |
// according to its (geometric|visible)Bounds | |
{ | |
var boundsProperty = ((visible)?'visible':'geometric')+'Bounds'; | |
var b = obj[boundsProperty]; | |
// width=right-left | |
return b[3]-b[1]; | |
} | |
function adjustTableWidths(relWidths) { | |
for(var T=0; T < myDoc.textFrames.length; T++){ | |
var frameWidth = getWidth(myDoc.textFrames[T], true); | |
for(var i=0; i < myDoc.textFrames[T].tables.length; i++){ | |
if(myDoc.textFrames[T].tables[i].columns.length == relWidths.length) { | |
for(var j=0; j < relWidths.length; j++){ | |
var colWidth = frameWidth * (relWidths[j] / 100); | |
myDoc.textFrames[T].tables[i].columns[j].width = colWidth; | |
} | |
} | |
} | |
} | |
} | |
adjustTableWidths([50,50]); | |
adjustTableWidths([26,44,20]); | |
alert("Table widths updated successfully!"); |
Sorry, I no longer have access to InDesign. Afraid you're on your own on this one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. This is no more working on the new indesign version. Can you fix it for the indesign 2025 ?
Thanks