Trouble with permanent crop code

Community Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Hi. I have a script that is meant to crop a pdf permanently by setting the media box to the crop box.

However when I run it I get the following error:

for(var i=0;i<this.numPages;i++)
var rCrop= this.getPageBox("Crop",i)
this.setPageBoxes("Media",i,i,rCrop)

TypeError: Invalid argument type.
Doc.setPageBoxes:1:Console undefined:Exec
===> Parameter nStart.

 

any help would be much appreciated.

Thanks

TOPICS
Acrobat SDK and JavaScript

Views

45

Likes

Translate

Translate

Report

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

Adobe Community Professional , Nov 24, 2020 Nov 24, 2020
Notice that the line number of the error is "1".  Are you executing this code one line at a time?  They need to be run all at the same time, but the "for" block also needs to be enclosed in brackets, and all the statements in the block need to end in a semicolon. Like this for(var i=0;i<this.numPages;i++) { var rCrop= this.getPageBox("Crop",i); this.setPageBoxes("Media",i,i,rCrop); } You'll find a tutorial on using the Console for exactly this sort of thing here: https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro...

Likes

Translate

Translate
Adobe Community Professional ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Notice that the line number of the error is "1".  Are you executing this code one line at a time?  They need to be run all at the same time, but the "for" block also needs to be enclosed in brackets, and all the statements in the block need to end in a semicolon. Like this

 

for(var i=0;i<this.numPages;i++)
{
   var rCrop= this.getPageBox("Crop",i);
    this.setPageBoxes("Media",i,i,rCrop);
}

 

 

You'll find a tutorial on using the Console for exactly this sort of thing here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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 Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

LATEST

Thanks so much!

Likes

Translate

Translate

Report

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