Skip to content

Commit

Permalink
Add :use_cursor option to PrawnOutputter, which makes it use and upda…
Browse files Browse the repository at this point in the history
…te Prawn's built-in cursor

This lets you output a human-readable barcode like this:

barcode = Barby::QrCode.new("http://toretore.eu/barby/")
Prawn::Document.generate("test.pdf") do |pdf|
  pdf.text "Visit this website:"
  barcode.annotate_pdf(pdf, :use_cursor => true)
  pdf.text barcode.data
end
  • Loading branch information
dlitz committed Apr 6, 2011
1 parent 4002c55 commit 15b1991
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/barby/outputter/prawn_outputter.rb
Expand Up @@ -7,7 +7,7 @@ class PrawnOutputter < Outputter

register :to_pdf, :annotate_pdf

attr_accessor :xdim, :ydim, :x, :y, :height, :margin, :unbleed
attr_accessor :xdim, :ydim, :x, :y, :height, :margin, :unbleed, :use_cursor


def to_pdf(opts={})
Expand All @@ -19,9 +19,15 @@ def to_pdf(opts={})

def annotate_pdf(pdf, opts={})
with_options opts do
xpos, ypos = x, y
xpos = x
orig_xpos = xpos

if use_cursor
ypos = pdf.y - pdf.bounds.absolute_bottom - height - margin
else
ypos = y
end

if barcode.two_dimensional?
boolean_groups.reverse_each do |groups|
groups.each do |bar,amount|
Expand Down Expand Up @@ -52,6 +58,8 @@ def annotate_pdf(pdf, opts={})
end
end

pdf.move_down(full_height) if use_cursor

end

pdf
Expand Down

0 comments on commit 15b1991

Please sign in to comment.