Sha256: 62dd6a2804ee6ea29f2ec081a6854efc4ca4c5094ac7c28b494c3ce38353850a

Contents?: true

Size: 916 Bytes

Versions: 3

Compression:

Stored size: 916 Bytes

Contents

#!/usr/bin/env ruby

require 'rubygems'
$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
      @content = nil
      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 ||= []
    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

3 entries across 3 versions & 1 rubygems

Version Path
pdf-reader-0.8.6 bin/pdf_text
pdf-reader-0.8.5 bin/pdf_text
pdf-reader-0.8.4 bin/pdf_text