Class: Barcodes::Renderer::Pdf
- Inherits:
-
Object
- Object
- Barcodes::Renderer::Pdf
- Defined in:
- lib/barcodes/renderer/pdf.rb
Overview
This class handles PDF rendering support.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#barcode ⇒ Object
The barcode instance.
Instance Method Summary collapse
-
#draw(pdf) ⇒ Object
Draws the barcode to the provided Prawn::Document.
-
#initialize(barcode = nil) ⇒ Pdf
constructor
Creates a new Barcodes::Renderer::Pdf instance.
-
#pdf ⇒ Object
Returns the instantiated Prawn::Document object.
-
#render(filename = nil) ⇒ Object
Render the barcode as PDF with optional filename.
Constructor Details
#initialize(barcode = nil) ⇒ Pdf
Creates a new Barcodes::Renderer::Pdf instance
18 19 20 |
# File 'lib/barcodes/renderer/pdf.rb', line 18 def initialize(=nil) @barcode = end |
Instance Attribute Details
#barcode ⇒ Object
The barcode instance
15 16 17 |
# File 'lib/barcodes/renderer/pdf.rb', line 15 def @barcode end |
Instance Method Details
#draw(pdf) ⇒ Object
Draws the barcode to the provided Prawn::Document
36 37 38 39 40 41 42 43 44 |
# File 'lib/barcodes/renderer/pdf.rb', line 36 def draw(pdf) if self..class == Barcodes::Symbology::Ean8 || self..class == Barcodes::Symbology::Ean13 || self..class == Barcodes::Symbology::UpcA self._draw_ean_upc(self., pdf) elsif self..class == Barcodes::Symbology::Planet || self..class == Barcodes::Symbology::Postnet self._draw_planet_postnet(self., pdf) else self._draw_standard(self., pdf) end end |
#pdf ⇒ Object
Returns the instantiated Prawn::Document object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/barcodes/renderer/pdf.rb', line 47 def pdf width = (@barcode.width * 0.001) * 72.0 height = (@barcode.height * 0.001) * 72.0 = { :page_size => [width, height], :left_margin => 0, :right_margin => 0, :top_margin => 0, :bottom_margin => 0 } Prawn::Document.new end |
#render(filename = nil) ⇒ Object
Render the barcode as PDF with optional filename
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/barcodes/renderer/pdf.rb', line 23 def render(filename=nil) pdf = self.pdf self.draw(pdf) unless filename.nil? pdf.render_file filename else pdf.render end end |