Skip to content

Instantly share code, notes, and snippets.

@narthur
Last active May 30, 2018 06:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narthur/ab7ae5fcc6a723e8bf6f to your computer and use it in GitHub Desktop.
Save narthur/ab7ae5fcc6a723e8bf6f to your computer and use it in GitHub Desktop.
InDesign JSX User Script to Adjust Table Widths Relative to Frame Width
// 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!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment