Class: Easyzpl::LabelTemplate
- Defined in:
- lib/easyzpl/label_template.rb
Overview
This is the label template object This gets uploaded and saved on the printer
Instance Attribute Summary collapse
-
#variable_fields_count ⇒ Object
Returns the value of attribute variable_fields_count.
Attributes inherited from Label
#field_orientation, #invert, #label_data, #label_height, #label_width, #pdf, #pdf_dpi, #printer_dpi, #quantity
Instance Method Summary collapse
-
#initialize(name, params = {}) ⇒ LabelTemplate
constructor
Called when the new method is invoked.
-
#variable_bar_code_39(x, y, params = {}) ⇒ Object
Sets a variable bar code that can be recalled.
-
#variable_bar_code_pdf417(x, y, params = {}) ⇒ Object
This creates a PDF417 bar code, which is very common in the automotive industry.
-
#variable_text_field(x, y, params = {}) ⇒ Object
Sets a variable field that can be recalled.
Methods inherited from Label
#bar_code_39, #bar_code_pdf417, #change_quantity, #draw_border, #home_position, #text_field, #to_pdf, #to_s
Constructor Details
#initialize(name, params = {}) ⇒ LabelTemplate
Called when the new method is invoked
15 16 17 18 19 20 21 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 |
# File 'lib/easyzpl/label_template.rb', line 15 def initialize(name, params = {}) return if name.nil? return if name.strip.empty? # Set the DPIs self.pdf_dpi = 72 self.printer_dpi = params[:dots] # Set the field orientation self.field_orientation = params[:field_orientation] # Set the number of variable fields self.variable_fields_count = 0 # Create the array that will hold the data self.label_data = [] # Set the default quantity to one self.quantity = 1 # See if invert is set to true self.invert = params[:invert] # The start of the label label_data.push('^XA') label_data.push('^POI') if invert label_data.push('^LT' + Integer(params[:offset] * printer_dpi).to_s) unless params[:offset].nil? label_data.push('^LL' + Integer(params[:height] * printer_dpi).to_s) unless params[:height].nil? label_data.push('^PW' + Integer(params[:width] * printer_dpi).to_s) unless params[:width].nil? label_data.push('^FWB') if field_orientation == :landscape label_data.push('^DF' + name + '^FS') # init_prawn(params) end |
Instance Attribute Details
#variable_fields_count ⇒ Object
Returns the value of attribute variable_fields_count.
12 13 14 |
# File 'lib/easyzpl/label_template.rb', line 12 def variable_fields_count @variable_fields_count end |
Instance Method Details
#variable_bar_code_39(x, y, params = {}) ⇒ Object
Sets a variable bar code that can be recalled
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/easyzpl/label_template.rb', line 82 def (x, y, params = {}) x = 0 unless numeric?(x) y = 0 unless numeric?(y) = { height: 0.1, width: 0.1 }.merge!(params) # update the variable field count self.variable_fields_count += 1 label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' + Integer(y * printer_dpi).to_s) label_data.push('^BY2,2,100') if params[:orientation] == :landscape label_data.push('^B3B,') else label_data.push('^B3N,') end label_data.push('Y,' + Integer([:height] * printer_dpi).to_s + ',N,N^FN' + variable_fields_count.to_s + '^FS') # return unless label_height && label_width # options = { height: 20 }.merge(params) # draw_bar_code_39('VARIABLEFIELD' + variable_fields_count.to_s, # Integer(x * pdf_dpi), Integer(y * pdf_dpi), # Integer(options[:height] * pdf_dpi)) end |
#variable_bar_code_pdf417(x, y, params = {}) ⇒ Object
This creates a PDF417 bar code, which is very common in the automotive industry. The format is as follows: ^B7o,h,s,c,r,t o = Orientation
N - normal, R rotated 90 degrees clockwise, I inverted 180 degrees
B - Read from bottom up 270 degrees
h = height for individual rows in dots
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/easyzpl/label_template.rb', line 117 def (x, y, params = {}) x = 0 unless numeric?(x) y = 0 unless numeric?(y) = { height: 0.1, width: 0.1 }.merge!(params) # update the variable field count self.variable_fields_count += 1 label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' + Integer(y * printer_dpi).to_s) if params[:orientation] == :landscape label_data.push('^B7B,') else label_data.push('^B7N,') end label_data.push((printer_dpi / 5).to_s + ',0,' + 5.to_s + ',' + 8.to_s + ',N^FN' + variable_fields_count.to_s + '^FS') end |
#variable_text_field(x, y, params = {}) ⇒ Object
Sets a variable field that can be recalled
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/easyzpl/label_template.rb', line 51 def variable_text_field(x, y, params = {}) x = 0 unless numeric?(x) y = 0 unless numeric?(y) = { height: 0.1, width: 0.1 }.merge!(params) # update the variable field count self.variable_fields_count += 1 label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' + Integer(y * printer_dpi).to_s) if params[:orientation] == :landscape label_data.push('^AFB,') else label_data.push('^AFN,') end label_data.push(Integer([:height] * printer_dpi).to_s + ',' + Integer([:width] * printer_dpi).to_s + '^FN' + variable_fields_count.to_s + '^FS') # return unless label_height > 0 && label_width > 0 # pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}', # at: [Integer(x * pdf_dpi), Integer(label_width * pdf_dpi) - # Integer(y * pdf_dpi) - # Integer(options[:height] / 10) * pdf_dpi], # size: Integer(options[:height] * pdf_dpi) if label_height && # label_width end |