The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Get the number from the txt file happyv UNIX for Dummies Questions & Answers 7 01-10-2008 03:51 AM
How to grep a number in a file to find them in another file ahjiefreak Shell Programming and Scripting 7 12-12-2007 06:01 AM
how to search string and number in one file and check in the other file knshree Shell Programming and Scripting 9 08-24-2007 04:29 AM
Number Swaping.... in file muneebr UNIX for Dummies Questions & Answers 3 12-17-2005 07:18 AM
Split text file by pages ranri UNIX for Dummies Questions & Answers 2 06-01-2001 02:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 2.50 average. Display Modes
  #1 (permalink)  
Old 03-04-2008
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
how to get number of pages in a PDF file

Hello,

Can anyone please help me providing script to get the number of pages in a PDF file?


TIA
Prvn
  #2 (permalink)  
Old 03-04-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Writing a script will not do it. Depending on the software that created the pdf and whether or not it is encrypted is way beyond shell, and probably something a casual C coder would want to try.

Your best bet is to find some software like pdf2txt. Then run it from the command line, and grep for ^L - ascii 12 - which is a page feed. There is probably something like pdf2txt in the open source area, ie., free. Try connecting to SourceForge.net: Welcome to SourceForge.net, use the search engine there, and find pdf conversion software.

Someone else here may know of a free product that is good. I don't.
  #3 (permalink)  
Old 03-08-2008
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 439
You might also try using pdf2ps if you have ghostscript, and then using:
"grep -c showpage" on the output file to count the number of pages.
  #4 (permalink)  
Old 03-08-2008
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
You could also try the pdftk app pdftk - the pdf toolkit

To get the number of pages:
pdftk file.pdf dump_data output | grep -i Num
NumberOfPages: 1
  #5 (permalink)  
Old 07-26-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
The following is a short shell script which I hacked together based on the PDF Reference V1.7 which seems to do the job across a wide spectrum of PDF document types.

Code:
#!/bin/ksh93
#
#  USAGE: pdfcount file.pdf
#

[[ "$#" != "1" ]] && {
   print "ERROR: No file specified"
   exit 1
}

numpages=0

strings $1 | grep "/Count" |
while read line
do
   num=${line/*([[:print:]])+(Count )?(-)+({1,4}(\d))*([[:print:]])/\4}
   (( num > numpages)) && numpages=$num
done

print $numpages

exit 0
Note this shell script is written for ksh93, not pdksh or ksh88. It can easily be ported to other shells but that I will leave as an exercise to the reader.
  #6 (permalink)  
Old 04-18-2009
ulibo ulibo is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
Hello

i´m interestet in your php code for pdf page nummber count.

br ulibo
  #7 (permalink)  
Old 04-20-2009
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
if you are familiar with Perl, check the PDF CPAN module

something like:
Code:
#!/usr/bin/perl
# get_pages_in_pdf_file.pl

use PDF;
my $filename = shift;

my $this_pdf = PDF->new;
$this_pdf = PDF->new($filename);

print "Has ", $this_pdf->Pages, " Pages \n";
Closed Thread

Bookmarks

Tags
count, count pages, ksh, page count, pdf, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0