Site logo

Crop pages in Acrobat

After the current issue of our magazine is ready, I create a pdf version of it for posting on a web-site. I merge single page pdf files into a single file and then I have to crop pages to remove printer marks. The issue is that the first two and the last two pages should be cropped with different parameters than all other pages. That´s why I wrote this script. I am not an expert in Acrobat scripting, I didn't even read the documentation, however I was able to figure out how to do what I need.

Acrobat is totally different beast than InDesign: no Scripts panel to double-click the script to run it. That is why you have to add a menu item by script.

app.addMenuItem({ cName: "Crop", cParent: "File",
	cExec: "crop();",
	cEnable: "event.rc = (event.target != null);",
	nPos: 0
});

function crop() {
	var tBox, newBox;
	var nPages = this.numPages;
	nPages = nPages-1;

	for (var i = 0; i <= nPages; i++) {
		if (i == 0 || i == (nPages-1)) {
			tBox = this.getPageBox("Crop", i);
			newBox = [ tBox[0]+650, tBox[1]-29, tBox[2]-27, tBox[3]+26 ];
			this.setPageBoxes({cBox: "Crop", nStart: i, nEnd: i, rBox: newBox});
		}
		else if (i == 1 || i == nPages) {
			tBox = this.getPageBox("Crop", i);
			newBox = [ tBox[0]+28, tBox[1]-29, tBox[2]-650, tBox[3]+26 ];
			this.setPageBoxes({cBox: "Crop", nStart: i, nEnd: i, rBox: newBox});
		}
		else {
			tBox = this.getPageBox("Trim", i);
			this.setPageBoxes({cBox: "Crop", nStart: i, nEnd: i, rBox: tBox})
		}
	}

	this.zoomType = zoomtype.fitP;
}