Hello,
Can anyone please help me providing script to get the number of pages in a PDF file?
TIA
Prvn
Hello,
Can anyone please help me providing script to get the number of pages in a PDF file?
TIA
Prvn
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.
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.
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
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.
#!/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.
Hello
i�m interestet in your php code for pdf page nummber count.
br ulibo
if you are familiar with Perl, check the PDF CPAN module
something like:
#!/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";
I�ve found the fpdi php class
<?php
require_once('fpdf16\fpdf.php');
require_once('fpdi13/fpdi.php');
$pdf =& new FPDI();
$pagecount = $pdf->setSourceFile('MyPDFDocument.pdf');
echo "Pagecount = ".$pagecount;
?>
This solves my Problem