Sha256: 0d93f99f49de8e6f5184a04fbc029502ab093ab2fbb8066c24647885e2eaac09

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby
# coding: utf-8

#  Basic RSpec of a generated PDF

require 'rubygems'
require 'pdf/reader'
require 'pdf/writer'
require 'spec'

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

context "My generated PDF" do
  specify "should have the correct text on 2 pages" do

    # generate our PDF
    pdf = PDF::Writer.new
    pdf.text "Chunky", :font_size => 32, :justification => :center
    pdf.start_new_page
    pdf.text "Bacon", :font_size => 32, :justification => :center
    pdf.save_as("chunkybacon.pdf")

    # process the PDF
    receiver = PageTextReceiver.new
    PDF::Reader.file("chunkybacon.pdf", receiver)

    # confirm the text appears on the correct pages
    receiver.content.size.should eql(2)
    receiver.content[0].should eql("Chunky")
    receiver.content[1].should eql("Bacon")
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
pdf-reader-0.10.1 examples/rspec.rb
fireinc-pdf-reader-0.11.0 examples/rspec.rb
fireinc-pdf-reader-0.11.0.alpha examples/rspec.rb
pdf-reader-0.11.0.alpha examples/rspec.rb
pdf-reader-0.10.0 examples/rspec.rb
pdf-reader-0.9.3 examples/rspec.rb
pdf-reader-0.9.2 examples/rspec.rb
pdf-reader-0.9.1 examples/rspec.rb
pdf-reader-0.9.0 examples/rspec.rb
pdf-reader-0.8.6 examples/rspec.rb
pdf-reader-0.8.5 examples/rspec.rb
pdf-reader-0.8.4 examples/rspec.rb
pdf-reader-0.8.3 examples/rspec.rb
pdf-reader-0.8.2 examples/rspec.rb
pdf-reader-0.8.1 examples/rspec.rb
pdf-reader-0.8.0 examples/rspec.rb
pdf-reader-0.7.7 examples/rspec.rb