Copy link to clipboard
Copied
Hi there,
I have used javascript from the community on here to list page size and count in a PDF.
There is one error (ReferenceError: A3Pages is not defined ) and wondering if anyone has advise on this please. I am new to this and don't know where A3 should be defined?
var msgText = "There are " + this.numPages + " pages in this document\n";
// counters
var numA4 = 0;
var numA3 = 0;
var numA2 = 0;
var numA1 = 0;
var numA0 = 0;
var p = .25;
// Values
var A4 = numA4*p;
var A3 = numA3*p;
var A2 = numA2*p;
var A1 = numA1*p;
var A0 = numA0*p;
var Sum = 0;
// helper function to compare a number with some wiggle room
function inRange(wid,hei,targetWid,targetHei) { var wiggle = 28; // amount of error to allow return (wid>=(targetWid-wiggle) && wid<=(targetWid+wiggle)) && (hei>=(targetHei-wiggle) && hei<=(targetHei+wiggle)) || (hei>=(targetWid-wiggle) && hei<=(targetWid+wiggle)) && (wid>= (targetHei-wiggle) && wid<=(targetHei+wiggle)) }
for (pagenum=0;pagenum<this.numPages;pagenum++) { var pbox = this.getPageBox("Crop",pagenum); var width = (pbox[2] - pbox[0]); var height = (pbox[1] - pbox[3]); var recognized = false;
if (inRange(width,height,595,842)) { numA4++; recognized = true; }
if (inRange(width,height,842,1191)) { numA3++; recognized = true; }
if (inRange(width,height,1191,1684)) { numA2++; recognized = true; }
if (inRange(width,height,1684,2384)) { numA1++; recognized = true; }
if (inRange(width,height,2384,3370)) { numA0++; recognized = true; }
if (!recognized) msgText += ("Page " + (pagenum+1) + " has a width of " + (width/72).toFixed(2) + " and a height of " + (height/72).toFixed(2) + "inches\n"); } msgText +=
numA4 + " A4 pages " + numA4*p + "\n"
+ numA3 + " A3 pages " + (numA3*p*2)
+ "\n" + numA2 + " A2 pages " + (numA2*p*4)
+ "\n" + numA1 + " A1 pages " + (numA1*p*8)
+ "\n" + numA0 + " A0 pages " + (numA0*p*16) + "\n"
+ (this.numPages++ - (numA4+numA3+numA2+numA1+numA0)) + " other pages"
+ "\n" + "sum " + (numA4*p+numA3*p*2+numA2*p*4+numA1*p*8+numA0*p*16);
app.alert(msgText);
Copy link to clipboard
Copied
Does you use A3Pages at a other script?
Copy link to clipboard
Copied
Hi Bernd, no I haven't used anyother script.
Copy link to clipboard
Copied
I doesn't get this error.
Copy link to clipboard
Copied
Oh ok. I did test the code with other PDF's and it seemed okay too. Attached are the results of what the code fetched, and where I saw the error for A3 ppages. I checked manually checked the page size on the PDF. It was mostly right, except the A3.
18 - A4
37 - A3
00 - A2
10 - A1
00 - A0
089 Other
Copy link to clipboard
Copied
Your screenshot shows the output of a other script.
Copy link to clipboard
Copied
Okay, I double check it. Thanks for your help.