Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Unable to get loop to work for crop

New Here ,
Dec 19, 2017 Dec 19, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
881
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 19, 2017 Dec 19, 2017

The Crop box is not enough. You need to also set the Media, and possibly the Trim, boxes as well.

Translate
Community Expert ,
Dec 19, 2017 Dec 19, 2017

Are the page sizes large enough?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2017 Dec 19, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2017 Dec 19, 2017

Change the first line to:

for (var i = 0; i < this.numPages; i++)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2017 Dec 19, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2017 Dec 19, 2017

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2017 Dec 19, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2017 Dec 19, 2017

The Crop box is not enough. You need to also set the Media, and possibly the Trim, boxes as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2017 Dec 19, 2017
LATEST

Thank you try67, and Bernd Alheit for the help works a treat now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines