• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

List Various page size & count , available in document.

Community Beginner ,
Dec 12, 2017 Dec 12, 2017

Copy link to clipboard

Copied

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..?

TOPICS
Create PDFs

Views

10.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 12, 2017 Dec 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,t

...

Votes

Translate

Translate
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

The value 2 is correct. 8 * 0.25 is 2.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

Your 100% correct, I was having a senior moment.

Although Ive still to test A1 and A0 sizes being detected correctly the corrected code is now working beautifully

FYI here it is, many thanks

---

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); 

---

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2023 Jun 19, 2023

Copy link to clipboard

Copied

Thanks For the code Guys, But i was checking a file with 6110 pages and the app alert just coming blank

can someone suggest a solution??

default305893163lbvzh_0-1687177027005.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2023 Jun 19, 2023

Copy link to clipboard

Copied

You've made an error, either in the variable name or somewhere els, like omitting a needed ";", or something else.

 

Do you know programming ? If yes, do you know JavaScript? 

ABAMBO | Hard- and Software Engineer | Photographer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Why didn't you use numA0, numA1, ... ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Can you use any other programs?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

An other program is not necessary.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

the code works perfectly
But I need you to also specify page numbers with a size other than A4
For example, if a PDF has 20 pages with different sizes, with the previous code I get this result: 

 

There are 20 pages in this document
10 pages A4
02 pages A3
04 pages A2
03 pages A1
01 pages A0  

 

But I need you to also specify the numbers of the pages with a size other than A4, like this: 

 

There are 20 pages in this document
10 pages A4
02 pages A3 - pages number: 4, 8
04 pages A2 - pages number: 11,12,13,14
03 pages A1 - pages number: 1,9,10
01 pages A0 - pages number: 5

 

can you help me???

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Well then, you're code needs to be a little bit more sophisticated. Add array variables for each size to collect page numbers. 

for example:

var A3Pages = [];

 ...

 

// inside loop

 if (inRange(width,height,842,1191)) { numA3++; recognized = true; A3Pages.push(pagenum+1); } 

 

Then just add the new variable to the display.

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Thank you so much for your quick response.
I am testing it but I still get the same result ....
I really have no idea of JavaScript !!
Please, could you put the whole code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

This is a pretty complicated script, so you ought to learn a bit about scripting. 

So, to see the page numbers you have to add the page number variable to the part of the script where the results are displayed. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Is there a way to show number of pages as a range? 

Pages in doc - 200
100 - A3 paper

PG. 6
PG. 7
....
100 - A4 paper
PG. 1
PG. 2
PG. 3
PG. 4
PG. 5

...

-------

I want to be shown like this:

100- A4 paper
PG. 1-5

 

Is there a way to do this?

Tnx in advance!

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

As long as the information exists, a script can be written to format the results any way you want. You just have to figure out the details. Determining page ranges from a list of page numbers is tricky, but doable. What kind of programming skills do you have? 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

quote

Is there a way to show number of pages as a range? 

Pages in doc - 200
100 - A3 paper

PG. 6
PG. 7
....
100 - A4 paper
PG. 1
PG. 2
PG. 3
PG. 4
PG. 5

...

-------

I want to be shown like this:

100- A4 paper
PG. 1-5

 

Is there a way to do this?

Tnx in advance!

 

 

 


By @Domac


You might be able to do it with Excel from a list of pages with same values.
You can do it it with ChatGPT as one off e.g.

convert the below page number, description to page range and description in a csv file:-
1,"A4"
2,"A4"
3,"A4"
4,"A4"
5,"A3"
6,"A3"
7,"A5"
8,"A5"
9,"A5"
10,"A4"
11,"A3"
12,"A4"

The output was:-
Page Range,Description
1-4,A4
5-6,A3
7-9,A5
10,A4
11,A3
12,A4

convert the below page number, description to grouped page range as one column and description in a csv file:-

Description,Range
A4,"1-4, 10-12"
A3,"5-6, 11"
A5,"7-9"


Clever stuff but 11 has been ranged so that is not correct.   Lee, Traction Software.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2023 Jul 19, 2023

Copy link to clipboard

Copied

Thank you guys for this grate script its very usefull.
I have a question. If i have custom size pagaes, is there any way to count together the same size pages?


E.g. I have 3 pages with 20x52 size, and some other pages.
Now the script create a list from it.
Page 1 size 20x52
Page 2 size 20x52

Page 3 size 20x52

 

Can it be counted together like the standard size pages?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2023 Jul 19, 2023

Copy link to clipboard

Copied

LATEST

Here is the script that I use for work, output is in Croatian but you can change it in the script.

 

console.println("Dokument se sastoji od " + this.numPages + " stranica");

// counters
var numA3 = 0;
var numA4 = 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)
);
}

var unrecognizedSizes = {};

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, 842, 1191)) {
numA3++;
recognized = true;
}
if (inRange(width, height, 595, 842)) {
numA4++;
recognized = true;
}
// etc...
if (!recognized) {
var dimString = (width * 0.3527777778).toFixed(0) + "x" + (height * 0.3527777778).toFixed(0);
if (unrecognizedSizes[dimString] === undefined) {
unrecognizedSizes[dimString] = [];
}
unrecognizedSizes[dimString].push(pagenum + 1);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
console.println("A4 papiri - " + numA4 + " komada");
var pageRanges = [];
var currentRange = null;

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)) {
recognized = true;
}
// etc...
if (recognized) {
if (currentRange === null) {
currentRange = {
start: pagenum + 1,
end: pagenum + 1,
};
} else {
currentRange.end = pagenum + 1;
}
numA4++; // Moved outside the `if (recognized)` block
} else if (currentRange !== null) {
pageRanges.push(currentRange);
currentRange = null;
}
}

if (currentRange !== null) {
pageRanges.push(currentRange);
}


var output = "";
for (var i = 0; i < pageRanges.length; i++) {
if (pageRanges[i].start === pageRanges[i].end) {
output += "," + pageRanges[i].start;
} else {
var lastRange = pageRanges[i-1];
if (lastRange && lastRange.end + 1 === pageRanges[i].start) {
output = output.slice(0, -2) + "-" + pageRanges[i].end + ",";
} else {
output += "," + pageRanges[i].start + "-" + pageRanges[i].end;
}
}
}

// Remove the initial comma
output = output.slice(1);

console.println(output);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
console.println( "A3 papiri - " + numA3 + " stranica");
var pageRanges = [];
var currentRange = null;

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

// etc...

if (recognized) {
if (currentRange === null) {
currentRange = {
start: pagenum + 1,
end: pagenum + 1
};
} else {
currentRange.end = pagenum + 1;
}
} else if (currentRange !== null) {
pageRanges.push(currentRange);
currentRange = null;
}
}

if (currentRange !== null) {
pageRanges.push(currentRange);
}
var output = "";
for (var i = 0; i < pageRanges.length; i++) {
if (pageRanges[i].start === pageRanges[i].end) {
output += "," + pageRanges[i].start;
} else {
var lastRange = pageRanges[i-1];
if (lastRange && lastRange.end + 1 === pageRanges[i].start) {
output = output.slice(0, -2) + "-" + pageRanges[i].end + ",";
} else {
output += "," + pageRanges[i].start + "-" + pageRanges[i].end;
}
}
}

// Remove the initial comma
output = output.slice(1);

console.println(output);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
console.println("Broj stranica ostalih formata:");

for (var dimString in unrecognizedSizes) {
var pages = unrecognizedSizes[dimString].sort(function(a, b){return a-b});
var pageRanges = [];
var rangeStart = null;
var rangeEnd = null;
for (var i = 0; i < pages.length; i++) {
if (rangeStart === null) {
rangeStart = pages[i];
rangeEnd = pages[i];
} else if (pages[i] === rangeEnd+1) {
rangeEnd = pages[i];
} else {
pageRanges.push([rangeStart, rangeEnd]);
rangeStart = pages[i];
rangeEnd = pages[i];
}
}
if (rangeStart !== null) {
pageRanges.push([rangeStart, rangeEnd]);
}
var rangeStrings = pageRanges.map(function(range){
if (range[0] === range[1]) {
return range[0];
} else {
return range[0] + "-" + range[1];
}
});
console.println(rangeStrings.join(",") + " sa dimenzijama " + dimString + " mm");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines