Last active
May 22, 2024 09:26
-
-
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 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!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment