Created
October 17, 2008 14:03
-
-
Save joshua/17418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'pdf/reader' | |
require 'rjb' | |
# Load Java classes | |
Rjb::load | |
PdfReader = Rjb::import('com.lowagie.text.pdf.PdfReader') | |
# Ruby PDF Reader Version | |
# Works...however(comma) RIDICULOUSLY slow | |
# Runtime: (153 page, 43.1MB PDF) Gave up @ 2m27.918s! | |
class PageReceiver | |
attr_accessor :pages | |
def page_count(arg) | |
@pages = arg | |
end | |
end | |
def ruby_page_count(file) | |
receiver = PageReceiver.new | |
pdf = PDF::Reader.file(file, receiver) | |
receiver.pages | |
end | |
# iText PDF Reader version, via RJB | |
# Lets see if this is any faster | |
# Runtime: (153 page, 43.1MB PDF) 0m1.541s! Who's Yur Daddy?! | |
def itext_page_count(file) | |
pdf = PdfReader.new(file) | |
pdf.getNumberOfPages | |
end | |
# Main | |
def main | |
pdfs = Dir["*.pdf"] | |
# pages = ruby_page_count pdfs[1] | |
pages = itext_page_count pdfs[1] | |
puts "#{pages} pages" | |
end | |
if $0 == __FILE__ | |
begin | |
main | |
rescue Exception | |
puts "Exception Caught: #{$!}" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment