Skip to main content
Nov 24, 2020 7:34 PM UTC
Answered

Trouble with permanent crop code

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

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Nov 24, 2020 8:15 PM UTC

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 PDFScriptingUse the Acrobat JavaScript Reference early and often

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Nov 24, 2020 8:15 PM UTC

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

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Nov 24, 2020 8:22 PM UTC

Thanks so much!

Translate