Skip to main content
November 24, 2020
Answered

Trouble with permanent crop code

  • November 24, 2020
  • 1 reply
  • 834 views

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 has been closed for replies.
Correct answer Thom Parker

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

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 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

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
November 24, 2020

Thanks so much!