Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created November 30, 2011 14:58
Show Gist options
  • Save floehopper/1409347 to your computer and use it in GitHub Desktop.
Save floehopper/1409347 to your computer and use it in GitHub Desktop.
require "pdf/reader"
class PageTextReceiver
attr_accessor :content
# Called when page parsing starts
def end_page(arg = nil)
if @content
puts @content
@content = nil
puts
end
end
def show_text(*params)
@content = "" if @content.nil?
params.each do |str|
@content << str.to_s
end
end
# there's a few text callbacks, so make sure we process them all
alias :super_show_text :show_text
alias :move_to_next_line_and_show_text :show_text
alias :set_spacing_next_line_show_text :show_text
def show_text_with_positioning(*params)
params = params.first
params ||= []
params.each { |str| show_text(str) if str.kind_of?(String)}
end
end
receiver = PageTextReceiver.new
PDF::Reader.file("~/Downloads/lmr110311.pdf", receiver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment