Skip to main content
Participating Frequently
December 12, 2017
Answered

List Various page size & count , available in document.

  • December 12, 2017
  • 1 reply
  • 13669 views

Dear ALL,

I have a document with multiple Page size eg its mixture of A3, A4 & letter size. Is there is any way that PDF can list the available page sizes & count of the no. eg

  • A4-4pages,
  • A3-12 pages,
  • A1-9pages,
  • letter -2 pages etc.

I would like to check before printing the document as it get stuck in printer due to non availabity of the right paper, eg A1, letter etc.. Please advice. Any Jawascript may work..?

This topic has been closed for replies.
Correct answer Dave Merchant

It's pretty simple to loop through the page sizes using JavaScript; here's a chunk of example code you can run from the console. Add more pages sizes as required, remember Acrobat measures everything in Points (72 pt per inch):

console.println("There are " + this.numPages + " pages in this document");

// counters

var numA3 = 0;

var numA4 = 0;

var numUSL = 0; // etc.

// helper function to compare a number with some wiggle room - we look for portrait and landscape possibilities

function inRange(wid,hei,targetWid,targetHei) {

    var wiggle = 2; // amount of error to allow in Points. Not all PDF software creates perfectly-sized pages

    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,841,1188)) { numA3++; recognized = true; }

    if (inRange(width,height,595,841)) { numA4++; recognized = true; }

    if (inRange(width,height,594,792)) { numUSL++; recognized = true; }

    // etc...

    if (!recognized) console.println("Page " + (pagenum+1) + " has a width of " + (width/72) + " and a height of " + (height/72) + "inches");

}

console.println(numA3 + " A3 pages");

console.println(numA4 + " A4 pages");

console.println(numUSL + " US Letter pages");

console.println((this.numPages++ - (numA3+numA4+numUSL)) + " other pages");

1 reply

try67
Adobe Expert
December 12, 2017

This can be done using a custom-made script. If you're interested in purchasing such a tool feel free to contact me privately at try6767 at gmail.com.

Mahesh6agAuthor
Participating Frequently
December 12, 2017

Thanks for your reply, looking for free options, I think your tool will be paid software. Anyway thank for your help.

Dave MerchantCorrect answer
Brainiac
December 12, 2017

It's pretty simple to loop through the page sizes using JavaScript; here's a chunk of example code you can run from the console. Add more pages sizes as required, remember Acrobat measures everything in Points (72 pt per inch):

console.println("There are " + this.numPages + " pages in this document");

// counters

var numA3 = 0;

var numA4 = 0;

var numUSL = 0; // etc.

// helper function to compare a number with some wiggle room - we look for portrait and landscape possibilities

function inRange(wid,hei,targetWid,targetHei) {

    var wiggle = 2; // amount of error to allow in Points. Not all PDF software creates perfectly-sized pages

    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,841,1188)) { numA3++; recognized = true; }

    if (inRange(width,height,595,841)) { numA4++; recognized = true; }

    if (inRange(width,height,594,792)) { numUSL++; recognized = true; }

    // etc...

    if (!recognized) console.println("Page " + (pagenum+1) + " has a width of " + (width/72) + " and a height of " + (height/72) + "inches");

}

console.println(numA3 + " A3 pages");

console.println(numA4 + " A4 pages");

console.println(numUSL + " US Letter pages");

console.println((this.numPages++ - (numA3+numA4+numUSL)) + " other pages");