LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-22-2009, 08:08 AM   #1
mfoley
Member
 
Registered: Oct 2008
Posts: 67

Rep: Reputation: 15
how to find PDF page count


Does anyone know where I can look in a PDF file to find the number of pages in the document?
 
Old 01-22-2009, 09:18 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949
The xpdf utilities package (called xpdf-utils in debian) includes an application called pdfinfo. It will print out the number of pages in the file, among other data.

You might also want to check out pdftk, which provides some useful tools for manipulating .pdf files.
 
Old 01-24-2009, 09:05 AM   #3
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

Rep: Reputation: 15
If you are opening it manually - it will be there at the foot of the Acrobat Reader application screen.


Linux Archive

Last edited by renjithrajasekaran; 01-25-2009 at 03:06 AM.
 
Old 01-24-2009, 12:28 PM   #4
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Try 'pdfinfo'.
 
Old 01-24-2009, 12:47 PM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Or pdftk, too:
Code:
pdftk file.pdf dump_data | grep NumberOfPages
 
Old 01-24-2009, 01:39 PM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Heck, I'll join the party. My favorite way is to use a PDF to PostScript tool, like pdf2ps. (If your system doesn't have that, just install Slackware, and you'll be all set.)
Code:
pdf2ps something.pdf something.ps
grep showpage something.ps | wc -l
 
Old 02-26-2009, 01:50 PM   #7
mfoley
Member
 
Registered: Oct 2008
Posts: 67

Original Poster
Rep: Reputation: 15
Someone suggested looking for /Count. That works, sort of ...

strings myfile.pdf | grep /Count

However, some files I have tested show multiple /Count entries:
/Count 1
/Count 4
/Count 1
/Count 5
/Count 1
/Count 6

In the examples I've tried, the highest number listed is the correct count. Any idea why I get multiple counts.
 
Old 02-26-2009, 02:48 PM   #8
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Ok if you want just the number of pages do this:

Code:
pdfinfo file.pdf | grep Pages | awk '{print $2}'
 
Old 02-26-2009, 02:55 PM   #9
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Why bother if you have other tools at hand?
Code:
$ pdfinfo file.pdf | grep Pages
$ pdftk file.pdf dump_data | grep NumberOfPages
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web page to PDF miykle Linux - Newbie 2 04-04-2008 05:07 AM
Printing html page to pdf with links MikeyCarter Linux - Software 1 11-16-2006 06:20 PM
Print PDF - blank page Trio3b Linux - General 1 12-10-2005 01:00 AM
Print web page to pdf under Gnome chocloman Slackware 2 04-28-2005 06:02 PM
can anyone print this pdf page? font problem doublefailure Linux - Software 2 03-23-2003 12:21 PM


All times are GMT -5. The time now is 11:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration