Class: Barby::PDFWriterOutputter
- Defined in:
- lib/barby/outputter/pdfwriter_outputter.rb
Overview
Annotates a PDFWriter document with the barcode
Registers the annotate_pdf method
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#x ⇒ Object
Returns the value of attribute x.
-
#xdim ⇒ Object
Returns the value of attribute xdim.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes inherited from Outputter
Instance Method Summary collapse
-
#annotate_pdf(pdf, options = {}) ⇒ Object
Annotate a PDFWriter document with the barcode.
Methods inherited from Outputter
#boolean_groups, #booleans, #encoding, #initialize, register, #two_dimensional?
Constructor Details
This class inherits a constructor from Barby::Outputter
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
12 13 14 |
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 12 def height @height end |
#x ⇒ Object
Returns the value of attribute x.
12 13 14 |
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 12 def x @x end |
#xdim ⇒ Object
Returns the value of attribute xdim.
12 13 14 |
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 12 def xdim @xdim end |
#y ⇒ Object
Returns the value of attribute y.
12 13 14 |
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 12 def y @y end |
Instance Method Details
#annotate_pdf(pdf, options = {}) ⇒ Object
Annotate a PDFWriter document with the barcode
Valid options are:
x, y - The point in the document to start rendering from height - The height of the bars in PDF units xdim - The X dimension in PDF units
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/barby/outputter/pdfwriter_outputter.rb', line 22 def annotate_pdf(pdf, ={}) do xpos, ypos = x, y orig_xpos = xpos if .two_dimensional? boolean_groups.reverse_each do |groups| groups.each do |,amount| if pdf.move_to(xpos, ypos). line_to(xpos, ypos+xdim). line_to(xpos+(xdim*amount), ypos+xdim). line_to(xpos+(xdim*amount), ypos). line_to(xpos, ypos). fill end xpos += (xdim*amount) end xpos = orig_xpos ypos += xdim end else boolean_groups.each do |,amount| if pdf.move_to(xpos, ypos). line_to(xpos, ypos+height). line_to(xpos+(xdim*amount), ypos+height). line_to(xpos+(xdim*amount), ypos). line_to(xpos, ypos). fill end xpos += (xdim*amount) end end end pdf end |