Skip to main content
Participant
March 31, 2023
Question

JavaScript Crop/Shift

  • March 31, 2023
  • 2 replies
  • 1165 views

Hello Everyone, I am scanning books. After scanning, i need to crop  all the pages. I set up a series of buttons to move the crop box around after resetting the mediabox to [0,792,612,0]. 

I crop all the pages and when going through it's as if I never touched the pages. 

I restore the page using this: 

/* Restore Crop and Media Box to 8.5 x 11 */
this.setPageBoxes("Crop",this.pageNum,this.pageNum,[0,792,612 ,0]);
this.setPageBoxes("Media",this.pageNum,this.pageNum,[0,792,612 ,0]);

/* Crop from ALL sides */
var rCrop = this.getPageBox("Crop",this.pageNum); 
rCrop[0] += 9; // Adjust Left Side 
rCrop[1] -= 65; // Adjust Top Side 
rCrop[2] -= 90; // Adjust Right Side 
rCrop[3] -= 0; // Adjust Bottom Side 
this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);

/* Shift */
var rCrop = this.getPageBox("Crop",this.pageNum); 
rCrop[0] += 9; // Adjust Left Side 
rCrop[1] -= 45; // Adjust Top Side 
rCrop[2] += 9; // Adjust Right Side 
rCrop[3] -= 45; // Adjust Bottom Side 
this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);

and then move or crop via buttons using the same code as above to either crop or shift but with different numbers. 

Is there anything in there that I am missing that applies the changes to more than the page that is visible? 

 

Thanks.

Patrick Brewer

This topic has been closed for replies.

2 replies

Participating Frequently
April 17, 2024

is there a javascript to image shift a mutipage document up, down, left and right?

BarlaeDC
Community Expert
Community Expert
April 4, 2023

Hi,

the setPageBoxes command takes the pages you want to apply it too:

In the code you have specified above you pass in

- nStart = this.pageNum

- nEnd = this.pageNum

if you want to apply it to more pages you need to specify the start and end pages to be different

- nStart = 0 // the first page in the document

- nEnd = this.pageNum -1 ; // the last page ( starts from zero)

 

and use those when you are wanting to apply it.