|
|||||||||
| Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here. |
linux operating commands and unix operating commands |
| Tags |
| count, count pages, ksh, page count, pdf, script |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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. |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
|
||||
|
||||
|
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 |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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 0Note 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. |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Hello
i´m interestet in your php code for pdf page nummber count. br ulibo |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
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"; |
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| file separated into paragraphs or pages | dodasajan | Shell Programming and Scripting | 3 | 11-24-2011 04:16 AM |
| creating pdf file with four pages | kristinu | UNIX for Advanced & Expert Users | 4 | 09-29-2011 10:48 PM |
| Finding what pages link to a specific file | iansocool | Shell Programming and Scripting | 2 | 08-26-2008 09:31 AM |
| Split text file by pages | ranri | UNIX for Dummies Questions & Answers | 2 | 06-01-2001 03:43 AM |
|
|