Reply To: How to resize Graphic to specific inches ?

#90628
Anonymous
Inactive

Here you are:

var main = function() {
var doc = app.properties.activeDocument;
if ( !doc || app.selection.length!=1 ) return;
if ( ! ( app.selection[0] instanceof Rectangle ) ){
alert(“Please select some container”);
return;
}
var rect =app.selection[0];
if ( !rect.graphics.length ) {
alert(“The item needs a placed graphic”);
return;
}
var graphic = rect.graphics[0];
var page = rect.properties.parentPage;
if ( !page ) {
alert(“The item is not placed on a page”);
return;
}
var pageBounds = page.bounds;
var docPrefs = doc.documentPreferences;
var facingPages = docPrefs.facingPages;
var side = page.side;
var right = side = PageSideOptions.RIGHT_HAND;
var insideBleed = docPrefs.documentBleedInsideOrLeftOffset;
var outsideBleed = docPrefs.documentBleedOutsideOrRightOffset;
pageBounds = [
pageBounds[0] – (docPrefs.documentBleedTopOffset ),
pageBounds[1] – (facingPages? (right? insideBleed : outsideBleed) : insideBleed ),
pageBounds[2] + ( docPrefs.documentBleedBottomOffset ),
pageBounds[3]+ ( facingPages? (right? outsideBleed : insideBleed) : outsideBleed )
];

var itemBounds = graphic.geometricBounds;
var itemHeight = Math.abs ( itemBounds[2]-itemBounds[0] );
var pageHeight = Math.abs ( pageBounds[2]-pageBounds[0] );
var pageWidth = Math.abs ( pageBounds[3]-pageBounds[1] );
var ratio = pageHeight/itemHeight;
const cs = CoordinateSpaces.INNER_COORDINATES,
ap = AnchorPoint.TOP_LEFT_ANCHOR,
rm = ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY;
graphic.resize ( cs, ap, rm, [ratio,ratio] );
itemBounds = graphic.geometricBounds;
var itemWidth = Math.abs ( itemBounds[3]-itemBounds[1] );
rect.visibleBounds = pageBounds;
graphic.move([(pageBounds[1]-(Math.max (itemWidth, pageWidth)-Math.min(itemWidth, pageWidth))/2),pageBounds[0]]);

}
var u;
app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

This article was last modified on December 20, 2016

Comments (0)

Loading comments...