Sha256: b8d6aa604611498db6f026e9d78bffeda9e664cdd9d3d0d3deea51a5e923ad11

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")

require 'pdf/reader'

class PageTextReceiver
  attr_accessor :content

  # Called when page parsing starts
  def end_page(arg = nil)
    if @content
      puts @content
      puts
    end
  end

  def show_text(string, *params)
    @content = "" if @content.nil?
    @content << string
  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.each { |str| show_text(str) if str.kind_of?(String)}
  end
end

receiver = PageTextReceiver.new

if ARGV.empty?
  PDF::Reader.new.parse($stdin, receiver)
else
  PDF::Reader.file(ARGV[0], receiver)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pdf-reader-0.7.2 bin/pdf_text