Copy link to clipboard
Copied
Dear java script kings,
I was checking the scripting for based on the xml work flow. Here with i faced the problem, images not fixed in the text frame width (attached screenshot for your reference).
@ I needed: All images automatically fit to text frame width and resizing images also.
Text frame width: 325.984 pt
Text frame hight: 535.748 pt
This passable to script?.
Advance Thanks
HTH,
...function main(){
var doc = app.properties.activeDocument,
rects, rect, n =0, columnWidth, ratio, rectBounds;
if(!doc) return;
rects = doc.stories.everyItem().rectangles.everyItem().getElements();
n = rects.length;
while ( n-- ) {
rect = rects
; if ( rect.parent.parentTextFrames.length ) {
columnWidth = rect.parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;
rectBounds = rect.visibleBounds;
ratio = columnWidth/(Math.abs(rectBounds[3]-rectBounds[1])
Copy link to clipboard
Copied
HTH,
function main(){
var doc = app.properties.activeDocument,
rects, rect, n =0, columnWidth, ratio, rectBounds;
if(!doc) return;
rects = doc.stories.everyItem().rectangles.everyItem().getElements();
n = rects.length;
while ( n-- ) {
rect = rects
; if ( rect.parent.parentTextFrames.length ) {
columnWidth = rect.parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth;
rectBounds = rect.visibleBounds;
ratio = columnWidth/(Math.abs(rectBounds[3]-rectBounds[1]));
rect.resize ( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [ratio,ratio] );
}
}
}
app.doScript( "main();", u,u, UndoModes.ENTIRE_SCRIPT, "Fit images to column" );
Loïc
Copy link to clipboard
Copied
Dear Loic.Aigon
Thanks so match for your response.
I try your coding and get back to you. one more thanks Loic.Aigon.
Thanks.
Copy link to clipboard
Copied
HI Loic.Aigon
First, sorry for the late replay.
I have run your above coding. That coding showed some error comment "u is undefined" (attached screen shot for your reference). I don't now how to clear this type problem friends.
One question: what is meaning for "u".
Advance Thanks,
Copy link to clipboard
Copied
My bad. You need to add this line prior to call doScript:
var u;
app.doScript…
u stands for undefined as it is actually…undefined.
Loic
Copy link to clipboard
Copied
HI Loic.Aigon,
Thank you so match friend. Your script working good.
One quick question: It is possible to reduced the image size in the java script? based no the text width frame. Please advice friend.
Advance Thanks
Copy link to clipboard
Copied
It's sure possible. Images are children of the rectangle object and have geometric properties you can take advantage of:
rect.graphics[0].geometricBounds = …
or rect.graphics[0].absoluteHorizontalScale = …
or rect.graphics[0].resize (…
or rect.graphics[0].transform (…
etc.
Copy link to clipboard
Copied
Hi Loic.Aigon,
OK, i will try your suggestion and get back to you.
Thanks