Thanks a lot, @bebarth for the fast reply.
Please, may I use this script with Acrobat Pro XI 11.0.23?
Here is the last script I used for the book I sent you back in PM:
d0=new Date();
starting=util.printd("mm/dd/yy – HH:MM:ss",d0);
var found=0;
for (var p=0; p<this.numPages; p++) {
console.clear();
console.println("Process starting: "+starting);
console.println("Processing the page #"+(p+1)+"/"+this.numPages);
if (this.getPageNumWords(p)) {
var thisPage=this.getPageBox("Crop",p);
var topAlign=780;
var bottomAlign=90;
var topLine=0;
var header="";
var bottomLine=0;
var footer="";
var topChapter=0;
var chapter="";
var leftMargin=Number(thisPage[2]);
var topMargin=0;
var rightMargin=0;
var bottomMargin=Number(thisPage[1]);
for (var i=0; i<this.getPageNumWords(p); i++) {
var pagination=0;
var q=this.getPageNthWordQuads(p,i);
var m=(new Matrix2D).fromRotated(this,p);
var mInv=m.invert();
var r=mInv.transform(q);
var r=r.toString();
var r=r.split(",");
if (Number(r[1])>35 && Number(r[1])<820) {
if (Number(r[1])>topAlign) {
if (!topLine && Number(r[0])<77) {
var header=header+this.getPageNthWord(p,i,true)+" - ";
var theAlignment="left";
} else if (Number(r[6])>590) {
header+="- "+this.getPageNthWord(p,i,true);
var theAlignment="right";
} else header+=this.getPageNthWord(p,i,false);
topLine++;
}
if (Number(r[1])<bottomAlign) {
bottomLine++;
//var footer=this.getPageNthWord(p,i,true);
}
if (Number(r[0])<leftMargin) leftMargin=Number(r[0]);
if (Number(r[1])>topMargin) topMargin=Number(r[1]);
if (Number(r[6])>rightMargin) rightMargin=Number(r[6]);
if (Number(r[7])<bottomMargin) bottomMargin=Number(r[7]);
}
}
this.setPageBoxes({
cBox: "Crop",
nStart: p,
rBox: [leftMargin-2,topMargin,rightMargin-2,bottomMargin-2]
});
var thisPage=this.getPageBox("Crop",p);
if (topLine && (theAlignment=="right" || (theAlignment=="left" && header.length<60))) {
var f=this.addField("header"+p,"text",p,[0,thisPage[1],thisPage[2],thisPage[1]-22]);
f.textSize=10;
f.alignment="center";
f.textFont=font.HelvB;
f.fillColor=color.white;
f.value=header;
}
if (bottomLine) {
var f=this.addField("footer"+p,"text",p,[0,12,thisPage[2],0]);
f.textSize=0;
f.alignment="center";
f.textFont=font.HelvB;
f.fillColor=color.white;
f.value=this.getPageLabel(p);
}
found++;
}
}
if (found) {
this.flattenPages();
this.saveAs(this.path.replace(/.pdf$/i," \(Cropped\).pdf"));
df=new Date();
ending=util.printd("mm/dd/yy – HH:MM:ss",df);
temps=(df.valueOf()-d0.valueOf())/1000/60;
var theMinutes=parseInt(temps);
var theSeconds=(temps-theMinutes)*60;
var theSeconds=parseInt(theSeconds*10)/10;
var theTime="";
if (theMinutes>0) {
if (theMinutes==1) var theTime="1 minute";
else var theTime=theMinutes+" minutes";
}
if (theSeconds>0) {
if (theSeconds<2) var theTime=theTime+" "+theSeconds+" second";
else var theTime=theTime+" "+theSeconds+" seconds";
}
var theTime=theTime.replace(/^\s+|\s+$/gm,"");
var plurial=found>1?"s":"";
var txt="Process starting: "+starting+"\rProcess ending: "+ending+"\rProcess duration: "+theTime+"\r\r"+found+"/"+this.numPages+" page"+plurial+" cropped.";
console.clear();
console.println(txt);
app.alert(txt,3);
}
Attached is a pdf file with a header and a footer you can use if some pages are not correct.
@+