Sha256: 0b0543b7224d092cd69d5b3de4ba09a762291f584f524e370a62f2bfbaf3e622

Contents?: true

Size: 1.89 KB

Versions: 10

Compression:

Stored size: 1.89 KB

Contents

# coding: utf-8

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

require 'pdf/wrapper'
require 'tempfile'
require 'rubygems'

gem "pdf-reader", ">=0.7.3"

require 'pdf/reader'

def create_pdf
  @output = StringIO.new
  @pdf = PDF::Wrapper.new(@output, :paper => :A4)
end

# make some private methods of PDF::Wrapper public for testing
class PDF::Wrapper
  public :build_pango_layout
  public :calc_image_dimensions
  public :default_text_options
  public :detect_image_type
  public :draw_pdf
  public :draw_pixbuf
  public :draw_png
  public :draw_svg
  public :image_dimensions
  public :load_librsvg
  public :load_libpixbuf
  public :load_libpango
  public :load_libpoppler
  public :user_x_to_device_x
  public :user_y_to_device_y
  public :device_x_to_user_x
  public :device_y_to_user_y
  public :validate_color
end

# a helper class for counting the number of pages in a PDF
class PageReceiver
  attr_accessor :pages

  def initialize
    @page_count = 0
  end

  # Called when page parsing ends
  def page_count(arg)
    @pages = arg
  end
end

# a helper class for recording the dimensions of pages in a PDF
class PageSizeReceiver
  attr_accessor :pages

  def initialize
    @pages = []
  end

  # Called when page parsing ends
  def begin_page(args)
    pages << (args["MediaBox"] || args[:MediaBox])
  end
end

class PageTextReceiver
  attr_accessor :content

  def initialize
    @content = []
  end

  # Called when page parsing starts
  def begin_page(arg = nil)
    @content << ""
  end

  def show_text(string, *params)
    @content.last << string.strip
  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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pdf-wrapper-0.4.1 specs/spec_helper.rb
pdf-wrapper-0.4.0 specs/spec_helper.rb
pdf-wrapper-0.3.5 specs/spec_helper.rb
pdf-wrapper-0.3.4 specs/spec_helper.rb
pdf-wrapper-0.3.3 specs/spec_helper.rb
pdf-wrapper-0.3.2 specs/spec_helper.rb
pdf-wrapper-0.3.1 specs/spec_helper.rb
pdf-wrapper-0.3.0 specs/spec_helper.rb
pdf-wrapper-0.2.1 specs/spec_helper.rb
pdf-wrapper-0.2.0 specs/spec_helper.rb