/ Published in: Ruby
I had a directory tree with around 4000 pdf files and I needed a page count - so I semi-rolled this. I swiped the counter code from the gem README:
http://github.com/yob/pdf-reader/tree/master
It could be more contained - as is I run it from irb:
`>> require 'total_pages'`
`>> pagetotal = TotalPages.new`
`>> pagetotal.count('/my/pdf/directory')`
I added rescue to print info on a file if it fails to open or doesn't conform to to the PDF specification and causes pdf-reader to raise an error - without this the script will quit - that sucks when you're trying to count pages in thousands of files.
http://github.com/yob/pdf-reader/tree/master
It could be more contained - as is I run it from irb:
`>> require 'total_pages'`
`>> pagetotal = TotalPages.new`
`>> pagetotal.count('/my/pdf/directory')`
I added rescue to print info on a file if it fails to open or doesn't conform to to the PDF specification and causes pdf-reader to raise an error - without this the script will quit - that sucks when you're trying to count pages in thousands of files.