How to get the lanscape page numbers from a whole pdf?  SOLVED

The PDF-XChange Viewer for End Users
+++ FREE +++

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
celk2010
User
Posts: 27
Joined: Tue Dec 17, 2019 3:33 am

How to get the lanscape page numbers from a whole pdf?

Post by celk2010 »

Hi, Everyone
Take one pdf book including 500 pages as an example, a few were landscape, the majority were portrait
How can I get the landscape pages numbers as soon as possible
The problem puzzled me for a very long time
Please help, thank you!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17908
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to get the lanscape page numbers from a whole pdf?

Post by Tracker Supp-Stefan »

Hello celk2010,

The quickest way would be to run the below JS code. To run it - use Ctrl + J on your keyboard to open the JS console, then copy and paste the entire script below, and then hit the Run button in the console. You should get a line with the result in the output area.

Code: Select all

var numLandscapePages = 0;
for (var i = 0; i<this.numPages; i++)
{
	var pageRect = this.getPageBox("Crop",i);
	var width = pageRect[2]-pageRect[0];
	var height = pageRect[1]-pageRect[3];
	if (width >= height) 
	{
		numLandscapePages++;
	}
}
console.println("There are "+ numLandscapePages + " landscape pages in this file");
Regards,
Stefan
celk2010
User
Posts: 27
Joined: Tue Dec 17, 2019 3:33 am

Re: How to get the lanscape page numbers from a whole pdf?

Post by celk2010 »

Hi, Dear Stefan,
If I have one pdf file, in total 10 pages, landscape pages are page 2, 4, 6,
By your code, the result will be "There are 3 landscape pages in this file"
Then I want to know exact pages numbers, just like: pages 2, 4, 6 are landscape pages.
How to achieve this goal?
Thank you!


Tracker Supp-Stefan wrote: Tue Dec 17, 2019 3:09 pm Hello celk2010,

The quickest way would be to run the below JS code. To run it - use Ctrl + J on your keyboard to open the JS console, then copy and paste the entire script below, and then hit the Run button in the console. You should get a line with the result in the output area.

Code: Select all

var numLandscapePages = 0;
for (var i = 0; i<this.numPages; i++)
{
	var pageRect = this.getPageBox("Crop",i);
	var width = pageRect[2]-pageRect[0];
	var height = pageRect[1]-pageRect[3];
	if (width >= height) 
	{
		numLandscapePages++;
	}
}
console.println("There are "+ numLandscapePages + " landscape pages in this file");
Regards,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17908
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to get the lanscape page numbers from a whole pdf?  SOLVED

Post by Tracker Supp-Stefan »

Hello celk2010,

A simple addition will output an additional line for each landscape page:

Code: Select all

var numLandscapePages = 0;
for (var i = 0; i<this.numPages; i++)
{
	var pageRect = this.getPageBox("Crop",i);
	var width = pageRect[2]-pageRect[0];
	var height = pageRect[1]-pageRect[3];
	if (width >= height) 
	{
		numLandscapePages++;
		console.println("Page "+ (i+1) + " is landscape");
	}
}
console.println("There are "+ numLandscapePages + " landscape pages in this file");
And if you want a list of all the landscape pages on a single line - something like this can be used:

Code: Select all

var numLandscapePages = 0;
var landscapePages = new Array ();
for (var i = 0; i<this.numPages; i++)
{
	var pageRect = this.getPageBox("Crop",i);
	var width = pageRect[2]-pageRect[0];
	var height = pageRect[1]-pageRect[3];
	if (width >= height) 
	{
		numLandscapePages++;
		landscapePages.push(i+1);
		console.println("Page "+ (i+1) + " is landscape"); //Comment this out by adding // at the front of the line if you do not want to see in the output a line for each landscape page.
	}
}
console.println("There are "+ numLandscapePages + " landscape pages in this file");
console.println("List of landscape pages "+ landscapePages);
Regards,
Stefan
celk2010
User
Posts: 27
Joined: Tue Dec 17, 2019 3:33 am

Re: How to get the lanscape page numbers from a whole pdf?

Post by celk2010 »

Thank you Stefan very much for your nice code, it have saved and will go on saving me much time.

My admiration for you is like a mighty river, even the seas run dry and the rocks crumble, the sky collapses and the earth cracks, I will never change my mind.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17908
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to get the lanscape page numbers from a whole pdf?

Post by Tracker Supp-Stefan »

Glad I could assist celk2010!

Season's greetings and
Kind Regards,
Stefan
celk2010
User
Posts: 27
Joined: Tue Dec 17, 2019 3:33 am

Re: How to get the lanscape page numbers from a whole pdf?

Post by celk2010 »

Merry Christmas to you Stefan!
Wish you a nice holiday!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17908
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to get the lanscape page numbers from a whole pdf?

Post by Tracker Supp-Stefan »

:)
Post Reply