bebarthCorrect answer
Community Expert
October 20, 2025
If it's possible for you to add marks to indicate the areas to be cropped, I think it's easier with square-type annotations.
In fact, the difficulty for you will come from the number of areas to indicate in the document, but if they're already drawn, that simplifies things a bit...
I've used this method in the past to crop different text areas in a document and extract them one by one.
This is an answer that certainly won't suit everyone, but it shows a possibility of using in JavaScript.
Here's a script that will do this:
var nbPages=this.numPages;
for (var p=0; p<nbPages; p++) {
var zones=[];
var annots=getAnnots({nPage:p});
if (annots!=null) {
for (var i=0; i<annots.length; i++) {
if (annots[i].type=="Square") {
zones.push(annots[i].rect);
}
}
for (var i=0; i<zones.length-1; i++) {
this.insertPages({
nPage: p,
cPath: this.path,
nStart: p
})
}
for (var i=0; i<zones.length; i++) {
this.setPageBoxes({
cBox: "Crop",
nStart: p+i,
rBox: zones[i]
})
}
}
p+=zones.length;
nbPages+=zones.length;
}
var annots=getAnnots();
for (var i=0; i<annots.length; i++) {
if (annots[i].type=="Square") annots[i].destroy();
}
this.saveAs(this.path.replace(/.pdf$/i,"_Cropped.pdf"));
Below, you will find your example on several pages before and after cropping.
@+

