in reply to Open a word(.doc) file and output the number of pages contained in it
perl -ne 'undef $/; $\="\n"; (($count = $1) =~ s/.*\Count\s*(\d+).*/\1/ && $pages < $count ? $pages=$1 : 1) while s/(<<[^<]*\/Type\s*\/Pages[^>]*>>)//; print $pages' somefile.pdf
I tested it one some pdf files and it seems to work. It is not a very elegant solutions and might be heavy for large files. It reads out the sections like the following in the PDF file and assumes that the larges count holds the number of pages, which is really an assumption.
23 0 obj << /Type /Pages /Resources 76 0 R /MediaBox [ 0 0 595 842 ] /Kids [ 24 0 R // and so on ] /Count 11 >> endobj
- wine
|
|---|