Do not distinguish the text box or picture frame, automatically fit to blood(not pages), automatically fit to the 4margins (I want to use less of the script to complete more things) Reference resources:https://forums.adobe.com/message/6146189
var curDoc = app.activeDocument;
if ( app.selection.length != 1 ) {
( alert ( "Something wrong with your selection!" ) );
exit();
}
var curSel = app.selection[0];
var curPage = curSel.parentPage;
// set the zeroPoint to 0
var zP = curDoc.zeroPoint;
if (zP != [0,0]) {
curDoc.zeroPoint = [0,0];
}
var rO = curDoc.viewPreferences.rulerOrigin;
if (rO != 1380143215) {
curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
}
var pW = curDoc.documentPreferences.pageWidth;
var y1, x1, y2, x2;
if ( curPage.side == PageSideOptions.leftHand ){
x2 = curPage.marginPreferences.left;
x1 = curPage.marginPreferences.right;
}
else {
x1 = curPage.marginPreferences.left;
x2 = curPage.marginPreferences.right;
}
x2 = pW - x2;
var gB = curSel.geometricBounds;
// fit to margins
/*gB[1] = x1;
gB[3] = x2;
curSel.geometricBounds = gB;
*/
// fit to page
gB[1] = 0;
gB[3] = pW;
curSel.geometricBounds = gB;
curSel.fit ( FitOptions.FRAME_TO_CONTENT );
resetAsBefore();
function resetAsBefore() {
if ( rO != 1380143215 ) {
curDoc.viewPreferences.rulerOrigin = rO;
}
// set the zeroPoint back to the origin state
if (zP != [0,0]) {
curDoc.zeroPoint = zP;
}
}
... View more