CHAPTER 3: Documents Adjusting Page Sizes and Layout 40
//Given a document with four pages (0, 1, 2, 3)...
var myDocument = app.activeDocument;
var myPages = myDocument.pages;
//Rotate a page around its center point.
var myRotateMatrix =
app.transformationMatrices.add({counterclockwiseRotationAngle:27});
myTransform(myPages.item(0), myRotateMatrix);
//Scale a page around its center point.
var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:0.8,
verticalScaleFactor:0.8});
myTransform(myPages.item(1), myScaleMatrix);
//Shear a page around its center point.
var myShearMatrix = app.transformationMatrices.add({clockwiseShearAngle:30});
myTransform(myPages.item(2), myShearMatrix);
function myTransform(myPage, myTransformationMatrix)
{
myPage.transform(CoordinateSpaces.PASTEBOARD_COORDINATES,
AnchorPoint.CENTER_ANCHOR,
myTransformationMatrix);
}
Master page overlay
Because pages can have multiple sizes, it is possible for a page and its master page to be different sizes. In
addition to tracking which master is applied, pages now also maintain a matrix that determines how the
master page draws on the page. This is called the Master Page Overlay. When you select a page using the
Page Tool on the Tools Panel, you can see how the master page is positioned by checking the Show Master
Page Overlay checkbox on the control panel. You can move the overlay around with the mouse. InDesign
achieves this by applying a transform to the master overlay matrix. Although the user interface allows only
translation (moving x and y), you can do more by scripting. The following script shows how to transform a
master page overlay. (For the complete script, see MasterPageTransform.)
//Given a document with four pages (0, 1, 2, 3)...
var myDocument = app.activeDocument;
var myPages = myDocument.pages;
//Rotate master page overlay around its top-left corner.
var myRotateMatrix =
app.transformationMatrices.add({counterclockwiseRotationAngle:27});
myPages.item(0).masterPageTransform = myRotateMatrix;
//Scale master page overlay around its top-left corner.
var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:0.5,
verticalScaleFactor:0.5});
myPages.item(1).masterPageTransform = myScaleMatrix;
//Shear master page overlay around its top-left corner.
var myShearMatrix =app.transformationMatrices.add({clockwiseShearAngle:30});
myPages.item(2).masterPageTransform = myShearMatrix;
//Translate master page overlay 1 inch right and 2 inches down.
var myTranslateMatrix = app.transformationMatrices.add({horizontalTranslation:72,
verticalTranslation:144});
myPages.item(3).masterPageTransform = myTranslateMatrix;