Copy link to clipboard
Copied
Hi,
I am trying to change the crop box by a 10th of its height and length on every page of a PDF.
So if the 1st page is 100 by 100 it would be come 110 by 110. If the second page is 200 by 200 it would become 220 by 220 leaving new white space to the top and right which I intend to add a watermark.
This seems to work fine, but for some reason its only working on the active page, and not looping thorough each page.
I am no Java expert so I am probably missing something very simple, here is my code:
for (var i = 0; i <= this.numPages; i++)
{
var rectCrop = this.getPageBox("Crop",i);
var width = rectCrop[2];
var height = rectCrop[1];
var new_width = width+width / 10;
var new_height = height+height / 10;
var rectNewCrop = [ 0, new_height, new_width, 0 ];
this.setPageBoxes("Crop", i, i, rectNewCrop);
}
It is hurting my brain trying to figure this out so any advice would be greatly appreciated.
Cheers,
Alistair
The Crop box is not enough. You need to also set the Media, and possibly the Trim, boxes as well.
Copy link to clipboard
Copied
Are the page sizes large enough?
Copy link to clipboard
Copied
The dimensions in the question above are an example, the document I have been testing this on is 8.5 x 11 in for the first 29 pages and the final page is 11 x 8.5 in.
I need to add white space and keep the page scaling.
I will be running this on many documents where the individual pages will often be different dimensions.
Copy link to clipboard
Copied
Change the first line to:
for (var i = 0; i < this.numPages; i++)
Copy link to clipboard
Copied
Still the same result, only one page is being cropped.
Interestingly, running this code on page one and, then on page two, changes page one back to its original dimensions, while page two is given the desired dimensions.
Copy link to clipboard
Copied
Try following with output of messages:
console.show();
for (var i = 0; i < this.numPages; i++)
{
var rectCrop = this.getPageBox("Crop",i);
console.println(rectCrop);
var width = rectCrop[2];
var height = rectCrop[1];
var new_width = width+width / 10;
var new_height = height+height / 10;
var rectNewCrop = [ 0, new_height, new_width, 0 ];
this.setPageBoxes("Crop", i, i, rectNewCrop);
rectCrop = this.getPageBox("Crop",i);
console.println(rectCrop);
}
Copy link to clipboard
Copied
This was the output for a 10 page PDF:
0,792,612,0
0,871.2000122070312,673.2000122070312,0
0,792,612,0
0,871.2000122070312,673.2000122070312,0
0,792,612,0
0,871.2000122070312,673.2000122070312,0
0,792,612,0
0,871.2000122070312,673.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
0,612,792,0
0,673.2000122070312,871.2000122070312,0
Copy link to clipboard
Copied
The Crop box is not enough. You need to also set the Media, and possibly the Trim, boxes as well.
Copy link to clipboard
Copied
Thank you try67, and Bernd Alheit for the help works a treat now.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now