Automated rotating and placing image and text on a

2019-09-09 17:37发布

问题:

I have been tasked with taking a set of product images and text and placing them in a booklet (with facing pages) and putting the product description next to the image.

Most images are landscape orientation whilst the book is portrait, and so they need to be rotated. For the images that have to be rotated, I'm placing the text in a textframe, fitting the frame to the content, then calculating the max image size, to then resize and then placing the image and rotating 90 / 270 degrees depending on whether the page is a left-hand or right-hand side page. This is rather long-winded for a rather simple operation of placing the image and text and rotating.

Is there a more automated method in InDesign, where it will rotate the image and textframe correctly depending on whether the page is left-hand or right-hand?

回答1:

Here is a javascript script that you can call:

const cs = CoordinateSpaces.pasteboardCoordinates,
ap = AnchorPoint.centerAnchor;

var main = function() {
	var doc = app.properties.activeDocument,
	gfxs, gfx, pg, par,
	mx90 = app.transformationMatrices.add({counterclockwiseRotationAngle:90}),
	mx270 = app.transformationMatrices.add({counterclockwiseRotationAngle:270});
	
	if ( !doc ) return;
	
	gfxs = doc.allGraphics;
	
	while ( gfx = gfxs.pop() ) {
		par = gfx.parent;
		par.locked = false;
		pg = par.parentPage;
		
		if  (pg instanceof Page) {
			par.transform ( cs, ap, pg.side==PageSideOptions.RIGHT_HAND? mx270 : mx90 );
		}

	}
}

var u;
app.doScript ( "main();", u, u, UndoModes.ENTIRE_SCRIPT );

For a real time execution you need to use it in combination with an event listener.