if (app.viewerVersion < 10){
app.addMenuItem({cName: "Pages sorter", cUser: "Pages sorter", cParent: "Tools", cExec: "PagesSorter()", cEnable: "event.rc=(event.target != null);"});
app.addMenuItem({cName: "Pages size", cUser: "Pages size", cParent: "Tools", cExec: "PagesSize()", cEnable: "event.rc=(event.target != null);"});
app.addMenuItem({cName: "Split by Pages size", cUser: "Split by Pages size", cParent: "Tools", cExec:"SplitByPagesSize()", cEnable: "event.rc=(event.target != null);"});
}
else {
app.addToolButton({cName: "Pages sorter", cLabel: "Pages sorter", cExec: "PagesSorter()", cEnable: "event.rc=(event.target != null);"});
app.addToolButton({cName: "Pages size", cLabel: "Pages size", cExec: "PagesSize()", cEnable: "event.rc=(event.target != null);"});
app.addToolButton({cName: "Split by Pages size", cLabel: "Split by Pages size", cExec: "SplitByPagesSize()", cEnable: "event.rc=(event.target != null);"});
}
function createRepHeader(doc, rep2Head){rep2Head.writeText("// Pages from " +doc.path+" sorted by sizes \n// All sizes in mm, based on Crop box\n");
}
PagesSorter=app.trustedFunction(function(){
app.beginPriv();
var aa=[];
var acp=[];
var cp, tmp, cc;
var nr=2.834;
var prec=0;
var linePerpage=59;
var ind=25;
if (this.numPages<2){
app.alert("Must be 2 or more pages in file");return -1;
}
var npw=0;
var nph=0;
var rep=new Report();
rep.size=1.2;
rep.writeText("PDF page by size sorter Copyright © VasЯ 2018");
createRepHeader(this, rep);
for (cc=0;cc<this.numPages;cc++){
aa.length=0;
for (cp=cc;cp<this.numPages;cp++){
ar=this.getPageBox("Crop", cp);
widthP=(ar[2]-ar[0])/nr;
heightP=(ar[1]-ar[3])/nr;
if (heightP>widthP){
tmp=heightP;
heightP=widthP;
widthP=tmp;
}aa.push({page:cp, width:widthP.toFixed(prec), height:heightP.toFixed(prec)});
};
aa.sort(function(a, b){if (a.width==b.width){
return a.height-b.height;
}else {
return a.width-b.width;
}});
this.movePage(aa[0].page, cc-1);
if ((aa[0].width != npw) || (aa[0].height != nph)){
npw=aa[0].width;
nph=aa[0].height;
acp.push({page:cc, width:aa[0].width, height:aa[0].height});
}}
rep.writeText("// Погрешность определения форматов составляет 5 мм ");
rep.writeText("// start page end page total pages width (mm) height (mm)");
rep.indent(ind);
for (tmp=0;tmp<acp.length-1;tmp++){
var ff;
//if (292<acp[tmp].width<302 && 205<acp[tmp].height<215){ ff="A4";}
if (205<acp[tmp].width<215 && 292<acp[tmp].height<302) {ff="A4"}
else{
//if (292<acp[tmp].width<302 && 415<acp[tmp].height<425){ ff="A3";}
if (415<acp[tmp].width<425 && 292<acp[tmp].height<302){ ff="A3"}
else{
//if (589<acp[tmp].width<599 && 415<acp[tmp].height<425){ ff="A2";}
if (415<acp[tmp].width<425 && 589<acp[tmp].height<599){ ff="A2"}
else{
//if (589<acp[tmp].width<599 && 836<acp[tmp].height<846){ ff="A1";}
if (836<acp[tmp].width<846 && 589<acp[tmp].height<599){ ff="A1"}
else{
//if (1184<acp[tmp].width<1194 && 836<acp[tmp].height<846){ ff="A0";}
if (836<acp[tmp].width<846 && 1184<acp[tmp].height<1194){ ff="A0"}
else {ff="неизвестный формат"}
}
}
}
}
rep.writeText((acp[tmp].page+1)+"\t\t"+acp[tmp+1].page + "\t\t"+ff+ " x " +((acp[tmp+1].page+1)-(acp[tmp].page+1))+ "\t\t"+acp[tmp].width+"\t\t"+acp[tmp].height);
if ((cc % linePerpage==0)&&(cc!=0)){
rep.breakPage();
createRepHeader(this, rep);
}}
// var ff;
//if (292<acp[tmp].width<302 && 205<acp[tmp].height<215){ ff="A4";}
//if (205<acp[tmp].width<215 && 292<acp[tmp].height<302){ ff="A4";}
//else{
//if (292<acp[tmp].width<302 && 415<acp[tmp].height<425){ ff="A3";}
//if (415<acp[tmp].width<425 && 292<acp[tmp].height<302){ ff="A3";}
//else{
//if (589<acp[tmp].width<599 && 415<acp[tmp].height<425){ ff="A2";}
//if (415<acp[tmp].width<425 && 589<acp[tmp].height<599){ ff="A2";}
//else{
Зарастание благодарю, дажен несли это не возможно!!!
//if (589<acp[tmp].width<599 && 836<acp[tmp].height<846){ ff="A1";}
//if (836<acp[tmp].width<846 && 589<acp[tmp].height<599){ ff="A1";}
//else{
//if (1184<acp[tmp].width<1194 && 836<acp[tmp].height<846){ ff="A0";}
//if (836<acp[tmp].width<846 && 1184<acp[tmp].height<1194){ ff="A0";}
//else {ff="неизвестный формат"}
//}
//}
//}
//}