easyzpl 0.2.6 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +229 -30
- data/lib/easyzpl/label.rb +74 -24
- data/lib/easyzpl/label_template.rb +83 -15
- data/lib/easyzpl/version.rb +1 -1
- data/spec/easyzpl_spec.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdcc330ffe5f7f22f24474f26e02103f9275314e
|
4
|
+
data.tar.gz: 8f45cc1ff0f3ef7f4a93b22a4da55780030324b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e4b73d16b62910fdb8be9119ccc098d1a03c3d9015859316be64398709003d99fcb1853093eb0a43558a2233346b24e4f18b6e16b653b641a3d9a0a590a7a31
|
7
|
+
data.tar.gz: 058939a1af37ebd19c6ae71ad37cc2159b15b393eb3740c835f674bef837ac34a0ac325ce5ac571db71c29f29efef9b0520d52038390519911decce6eb6dfda0
|
data/README.md
CHANGED
@@ -23,37 +23,236 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
$ gem install easyzpl
|
25
25
|
|
26
|
-
## Usage
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# Create a simple label
|
32
|
-
# NOTE: The height and width parameters are optional.
|
33
|
-
# You only need to use them if you plan on using the
|
34
|
-
# to_pdf method.
|
35
|
-
label = Easyzpl::Label.new({ width: 400, height: 300 })
|
36
|
-
label.home_position(30, 30)
|
37
|
-
label.draw_border(0, 0, 400, 300)
|
38
|
-
label.text_field('ZEBRA', 10, 10)
|
39
|
-
label.bar_code_39('ZEBRA', 10, 30)
|
40
|
-
puts label.to_s
|
41
|
-
label.to_pdf("label.pdf")
|
42
|
-
|
43
|
-
# Create a stored template
|
44
|
-
label = Easyzpl::LabelTemplate.new('Template1')
|
45
|
-
label.home_position(30, 30)
|
46
|
-
label.draw_border(0, 0, 400, 300)
|
47
|
-
label.variable_text_field(10, 10)
|
48
|
-
label.variable_bar_code_39(10, 30)
|
49
|
-
puts label.to_s
|
50
|
-
|
51
|
-
# Created ZPL code to access the stored template created above
|
52
|
-
label = Easyzpl::StoredLabel.new('Template1')
|
53
|
-
label.add_field('ZEBRA')
|
54
|
-
label.add_field('ZEBRA')
|
55
|
-
puts label.to_s
|
26
|
+
## Usage - the following is an example of an AIAG template
|
27
|
+
```
|
28
|
+
# This file generates the ZPL for the AIAG template
|
29
|
+
require 'rubygems'
|
30
|
+
require 'easyzpl'
|
56
31
|
|
32
|
+
# There are 72 dots in an inch (usually)
|
33
|
+
# In the case of our printer, there are 203
|
34
|
+
dots = 193
|
35
|
+
|
36
|
+
# The dimensions of the label
|
37
|
+
label_x = 0
|
38
|
+
label_y = 0
|
39
|
+
label_width = 4
|
40
|
+
label_height = 6.5
|
41
|
+
label_fields_orientation = :landscape
|
42
|
+
|
43
|
+
# The dimensions of the header border
|
44
|
+
header_width = 1.2
|
45
|
+
header_height = 6.5
|
46
|
+
header_x = 0
|
47
|
+
header_y = 0
|
48
|
+
|
49
|
+
# The dimensions of the quantity border
|
50
|
+
quant_x = header_width
|
51
|
+
quant_y = header_height - (label_height / 2)
|
52
|
+
quant_height = label_height / 2
|
53
|
+
quant_width = 1.1
|
54
|
+
|
55
|
+
# The quantity text label
|
56
|
+
quant_text_label = 'QUANTITY'
|
57
|
+
quant_text_x = header_width + 0.1
|
58
|
+
quant_text_y = label_height - (quant_height - 2.5)
|
59
|
+
quant_text_height = 0.1
|
60
|
+
quant_text_width = 0.1
|
61
|
+
|
62
|
+
# The actual quantity text
|
63
|
+
qty_x = header_width + 0.1
|
64
|
+
qty_y = label_height - (quant_height - 0.5)
|
65
|
+
qty_width = 0.1
|
66
|
+
qty_height = 0.1
|
67
|
+
|
68
|
+
# The quantity bar code
|
69
|
+
qty_bar_code_x = header_width + 0.1 + 0.3
|
70
|
+
qty_bar_code_y = label_height - (quant_height - 0.5)
|
71
|
+
qty_bar_code_height = 0.3
|
72
|
+
|
73
|
+
# The dimensions of the serial supplier border
|
74
|
+
supplier_x = header_width + quant_width
|
75
|
+
supplier_y = header_height - 4
|
76
|
+
supplier_width = 0.8
|
77
|
+
supplier_height = 4
|
78
|
+
|
79
|
+
# The dimensions of the serial serial border
|
80
|
+
serial_x = header_width + quant_width + supplier_width
|
81
|
+
serial_y = header_height - 4
|
82
|
+
serial_width = 0.92
|
83
|
+
serial_height = 4
|
84
|
+
|
85
|
+
# The Header Text
|
86
|
+
header_text_x = 0.1
|
87
|
+
header_text_y = 0.001
|
88
|
+
header_text_height = 1.0
|
89
|
+
header_text_width = 0.5
|
90
|
+
|
91
|
+
# Supplier Name
|
92
|
+
supplier_name = 'Some Company'
|
93
|
+
supplier_name_x = header_width + 0.1
|
94
|
+
supplier_name_y = 0.2
|
95
|
+
supplier_name_height = 0.1
|
96
|
+
supplier_name_width = 0.1
|
97
|
+
|
98
|
+
# Supplier Address
|
99
|
+
supplier_address = '253 Street Name'
|
100
|
+
supplier_address_x = header_width + supplier_name_height + 0.15
|
101
|
+
supplier_address_y = 0.2
|
102
|
+
supplier_address_height = 0.1
|
103
|
+
supplier_address_width = 0.1
|
104
|
+
|
105
|
+
# Supplier city\state
|
106
|
+
supplier_city_state = 'City, FL 32953'
|
107
|
+
supplier_city_state_x = header_width + supplier_name_height + supplier_address_height + 0.2
|
108
|
+
supplier_city_state_y = 0.2
|
109
|
+
supplier_city_state_height = 0.1
|
110
|
+
supplier_city_state_width = 0.1
|
111
|
+
|
112
|
+
# The supplier header that goes in the supplier bar code box
|
113
|
+
supplier_header = 'SUPPLIER'
|
114
|
+
supplier_header_width = 0.1
|
115
|
+
supplier_header_height = 0.1
|
116
|
+
supplier_header_x = header_width + quant_width + 0.1
|
117
|
+
supplier_header_y = label_height - 0.75 - supplier_header_width
|
118
|
+
|
119
|
+
# The supplier number that goes in the supplier bar code box
|
120
|
+
supplier_number_x = header_width + quant_width + 0.1
|
121
|
+
supplier_number_y = label_height - 3.5 - supplier_header_width
|
122
|
+
supplier_number_height = 0.1
|
123
|
+
supplier_number_width = 0.1
|
124
|
+
|
125
|
+
# The supplier bar code that goes in the supplier bar code box
|
126
|
+
supplier_bar_code_x = header_width + quant_width + supplier_number_height + 0.2
|
127
|
+
supplier_bar_code_y = label_height - 3.5 - supplier_header_width
|
128
|
+
supplier_bar_code_height = 0.3
|
129
|
+
|
130
|
+
## The serial number header that goes in the serial number bar code box
|
131
|
+
serial_header = 'SERIAL'
|
132
|
+
serial_header_height = 0.1
|
133
|
+
serial_header_width = 0.1
|
134
|
+
serial_header_x = header_width + quant_width + supplier_width + 0.1
|
135
|
+
serial_header_y = label_height - 0.75 - serial_header_width
|
136
|
+
|
137
|
+
# The serial number that goes in the serial number bar code box
|
138
|
+
serial_number_width = 0.1
|
139
|
+
serial_number_height = 0.1
|
140
|
+
serial_number_x = header_width + quant_width + supplier_width + 0.1
|
141
|
+
serial_number_y = label_height - 3.5 - serial_header_width
|
142
|
+
|
143
|
+
# The serial bar code that goes in the serial number bar code box
|
144
|
+
serial_bar_code_x = header_width + quant_width + supplier_width + serial_number_height + 0.2
|
145
|
+
serial_bar_code_y = label_height - 3.5 - serial_header_width
|
146
|
+
serial_bar_code_height = 0.3
|
147
|
+
|
148
|
+
# Generate the new label
|
149
|
+
label = Easyzpl::LabelTemplate.new('AiagLabel',
|
150
|
+
dots: dots,
|
151
|
+
width: label_width,
|
152
|
+
field_orientation: label_fields_orientation,
|
153
|
+
height: label_height)
|
154
|
+
|
155
|
+
label.home_position(30, 30) # 30,30 seems to be the standard for Zebra labels
|
156
|
+
|
157
|
+
# Draw the border around the entire label
|
158
|
+
label.draw_border(label_x, label_y, label_width, label_height)
|
159
|
+
|
160
|
+
# Draw the header border
|
161
|
+
label.draw_border(header_x, header_y, header_width, header_height)
|
162
|
+
|
163
|
+
# Draw the quantity border
|
164
|
+
label.draw_border(quant_x, quant_y, quant_width, quant_height)
|
165
|
+
|
166
|
+
# Draw the supplier border
|
167
|
+
label.draw_border(supplier_x, supplier_y, supplier_width, supplier_height)
|
168
|
+
|
169
|
+
# Draw the serial border
|
170
|
+
label.draw_border(serial_x, serial_y, serial_width, serial_height)
|
171
|
+
|
172
|
+
# Print the header text
|
173
|
+
label.variable_text_field(header_text_x, header_text_y,
|
174
|
+
width: header_text_width, height: header_text_height)
|
175
|
+
|
176
|
+
# Print the quantity label
|
177
|
+
label.text_field(quant_text_label,
|
178
|
+
quant_text_x,
|
179
|
+
quant_text_y,
|
180
|
+
width: quant_text_width,
|
181
|
+
height: quant_text_height)
|
182
|
+
|
183
|
+
# Print the quantity
|
184
|
+
label.variable_text_field(qty_x,
|
185
|
+
qty_y,
|
186
|
+
width: qty_width,
|
187
|
+
height: qty_height)
|
188
|
+
|
189
|
+
# Print the quantity bar code
|
190
|
+
label.variable_bar_code_39(qty_bar_code_x,
|
191
|
+
qty_bar_code_y,
|
192
|
+
orientation: :landscape,
|
193
|
+
height: qty_bar_code_height)
|
194
|
+
|
195
|
+
# Print the supplier name and address
|
196
|
+
label.text_field(supplier_name,
|
197
|
+
supplier_name_x,
|
198
|
+
supplier_name_y,
|
199
|
+
width: supplier_name_width,
|
200
|
+
height: supplier_name_height)
|
201
|
+
|
202
|
+
label.text_field(supplier_address,
|
203
|
+
supplier_address_x,
|
204
|
+
supplier_address_y,
|
205
|
+
width: supplier_address_width,
|
206
|
+
height: supplier_address_height)
|
207
|
+
|
208
|
+
label.text_field(supplier_city_state,
|
209
|
+
supplier_city_state_x,
|
210
|
+
supplier_city_state_y,
|
211
|
+
width: supplier_city_state_width,
|
212
|
+
height: supplier_city_state_height)
|
213
|
+
|
214
|
+
# Print the supplier header
|
215
|
+
label.text_field(supplier_header,
|
216
|
+
supplier_header_x,
|
217
|
+
supplier_header_y,
|
218
|
+
width: supplier_header_width,
|
219
|
+
height: supplier_header_height)
|
220
|
+
|
221
|
+
# Print the supplier number
|
222
|
+
label.variable_text_field(supplier_number_x,
|
223
|
+
supplier_number_y,
|
224
|
+
width: supplier_number_width,
|
225
|
+
height: supplier_number_height)
|
226
|
+
|
227
|
+
# Print the supplier bar code
|
228
|
+
label.variable_bar_code_39(supplier_bar_code_x,
|
229
|
+
supplier_bar_code_y,
|
230
|
+
orientation: :landscape,
|
231
|
+
height: supplier_bar_code_height)
|
232
|
+
|
233
|
+
# Print the serial header
|
234
|
+
label.text_field(serial_header,
|
235
|
+
serial_header_x,
|
236
|
+
serial_header_y,
|
237
|
+
orientation: :landscape,
|
238
|
+
height: serial_header_height,
|
239
|
+
width: serial_header_width)
|
240
|
+
|
241
|
+
# Print the serial number
|
242
|
+
label.variable_text_field(serial_number_x,
|
243
|
+
serial_number_y,
|
244
|
+
height: serial_number_height,
|
245
|
+
width: serial_number_width)
|
246
|
+
|
247
|
+
# Print the serial bar code
|
248
|
+
label.variable_bar_code_39(serial_bar_code_x,
|
249
|
+
serial_bar_code_y,
|
250
|
+
orientation: :landscape,
|
251
|
+
height: serial_bar_code_height)
|
252
|
+
|
253
|
+
# Generate the label code
|
254
|
+
puts label.to_s
|
255
|
+
```
|
57
256
|
## Contributing
|
58
257
|
|
59
258
|
1. Fork it ( https://github.com/[my-github-username]/easyzpl/fork )
|
data/lib/easyzpl/label.rb
CHANGED
@@ -7,24 +7,44 @@ require 'barby/outputter/prawn_outputter'
|
|
7
7
|
module Easyzpl
|
8
8
|
# This is the label object
|
9
9
|
class Label
|
10
|
+
attr_accessor :invert
|
10
11
|
attr_accessor :label_data
|
11
12
|
attr_accessor :quantity
|
12
13
|
attr_accessor :pdf
|
13
14
|
attr_accessor :label_width
|
14
15
|
attr_accessor :label_height
|
16
|
+
attr_accessor :printer_dpi
|
17
|
+
attr_accessor :pdf_dpi
|
18
|
+
attr_accessor :field_orientation
|
15
19
|
|
16
20
|
# Called when the new method is invoked
|
17
21
|
def initialize(params = {})
|
18
22
|
# Create the array that will hold the data
|
19
23
|
self.label_data = []
|
24
|
+
|
20
25
|
# Set the default quantity to one
|
21
26
|
self.quantity = 1
|
22
27
|
|
23
|
-
#
|
28
|
+
# Set the DPIs
|
29
|
+
self.pdf_dpi = 72
|
30
|
+
self.printer_dpi = params[:dots]
|
31
|
+
|
32
|
+
# Set the field orientation
|
33
|
+
self.field_orientation = params[:field_orientation]
|
34
|
+
|
35
|
+
# See if invert is set to true
|
36
|
+
self.invert = params[:invert]
|
37
|
+
|
38
|
+
# The start of the label
|
24
39
|
label_data.push('^XA')
|
40
|
+
label_data.push('^POI') if invert
|
41
|
+
label_data.push('^LT' + Integer(params[:offset] * printer_dpi).to_s) unless params[:offset].nil?
|
42
|
+
label_data.push('^LL' + Integer(params[:height] * printer_dpi).to_s) unless params[:height].nil?
|
43
|
+
label_data.push('^PW' + Integer(params[:width] * printer_dpi).to_s) unless params[:width].nil?
|
44
|
+
label_data.push('^FWB') if field_orientation == :landscape
|
25
45
|
|
26
46
|
# Initialize Prawn
|
27
|
-
init_prawn(params)
|
47
|
+
# init_prawn(params)
|
28
48
|
end
|
29
49
|
|
30
50
|
# Set the number of labels to print
|
@@ -48,38 +68,66 @@ module Easyzpl
|
|
48
68
|
x = 0 unless numeric?(x)
|
49
69
|
y = 0 unless numeric?(y)
|
50
70
|
|
51
|
-
label_data.push('^FO' + x
|
52
|
-
|
71
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
72
|
+
Integer(y * printer_dpi).to_s + '^GB' +
|
73
|
+
Integer(height * printer_dpi).to_s +
|
74
|
+
',' + Integer(width * printer_dpi).to_s + ',1^FS')
|
53
75
|
|
54
|
-
draw_rectangle(x, y, height, width)
|
76
|
+
# draw_rectangle(x * pdf_dpi, y * pdf_dpi, height * pdf_dpi, width * pdf_dpi)
|
55
77
|
end
|
56
78
|
|
57
79
|
# Prints text
|
58
80
|
def text_field(text, x, y, params = {})
|
59
81
|
x = 0 unless numeric?(x)
|
60
82
|
y = 0 unless numeric?(y)
|
61
|
-
options = { height:
|
62
|
-
|
63
|
-
|
64
|
-
|
83
|
+
options = { height: 0.1,
|
84
|
+
width: 0.1 }.merge!(params)
|
85
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' + Integer(y *
|
86
|
+
printer_dpi).to_s)
|
87
|
+
|
88
|
+
if params[:orientation] == :landscape
|
89
|
+
label_data.push('^AFB,')
|
90
|
+
else
|
91
|
+
label_data.push('^AFN,')
|
92
|
+
end
|
65
93
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
94
|
+
label_data.push(Integer(options[:height] * printer_dpi).to_s + ',' +
|
95
|
+
Integer(options[:width] * printer_dpi).to_s + '^FD' +
|
96
|
+
text + '^FS')
|
97
|
+
|
98
|
+
# return unless label_height > 0 && label_width > 0
|
99
|
+
# pdf.text_box text, at: [x, label_width - y -
|
100
|
+
# Integer((options[:height] * pdf_dpi) / 10)],
|
101
|
+
# size: (options[:height] *
|
102
|
+
# pdf_dpi) if label_height && label_width
|
71
103
|
end
|
72
104
|
|
73
105
|
# Prints a bar code in barcode39 font
|
74
106
|
def bar_code_39(bar_code_string, x, y, params = {})
|
75
107
|
x = 0 unless numeric?(x)
|
76
108
|
y = 0 unless numeric?(y)
|
77
|
-
label_data.push('^FO' + x
|
109
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
110
|
+
Integer(y * printer_dpi).to_s + '^B3N,Y,20,N,N^FD' +
|
78
111
|
bar_code_string + '^FS')
|
79
112
|
|
80
|
-
return unless label_height && label_width
|
81
|
-
options = { height: 20 }.merge(params)
|
82
|
-
draw_bar_code_39(bar_code_string, x
|
113
|
+
# return unless label_height && label_width
|
114
|
+
# options = { height: 20 }.merge!(params) { |key, v1, v2| v1 }
|
115
|
+
# draw_bar_code_39(bar_code_string, Integer(x * pdf_dpi),
|
116
|
+
# Integer(y * pdf_dpi), (options[:height] * pdf_dpi))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Prints a bar code in pdf417 font
|
120
|
+
def bar_code_pdf417(bar_code_string, x, y, params = {})
|
121
|
+
x = 0 unless numeric?(x)
|
122
|
+
y = 0 unless numeric?(y)
|
123
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
124
|
+
Integer(y * printer_dpi).to_s + '^B7N,Y,20,N,N^FD' +
|
125
|
+
bar_code_string + '^FS')
|
126
|
+
|
127
|
+
# return unless label_height && label_width
|
128
|
+
# options = { height: 20 }.merge!(params)
|
129
|
+
# draw_bar_code_39(bar_code_string, Integer(x * pdf_dpi),
|
130
|
+
# Integer(y * pdf_dpi), (options[:height] * pdf_dpi))
|
83
131
|
end
|
84
132
|
|
85
133
|
# Renders the ZPL code as a string
|
@@ -96,8 +144,8 @@ module Easyzpl
|
|
96
144
|
protected
|
97
145
|
|
98
146
|
def init_prawn(params)
|
99
|
-
self.label_width = params[:width] || 0
|
100
|
-
self.label_height = params[:height] || 0
|
147
|
+
self.label_width = (params[:width] * pdf_dpi) || 0
|
148
|
+
self.label_height = (params[:height] * pdf_dpi) || 0
|
101
149
|
|
102
150
|
return unless label_height > 0 && label_width > 0
|
103
151
|
self.pdf = Prawn::Document.new
|
@@ -113,17 +161,19 @@ module Easyzpl
|
|
113
161
|
return unless label_height > 0 && label_width > 0
|
114
162
|
pdf.stroke_axis
|
115
163
|
pdf.stroke do
|
116
|
-
pdf.rectangle [x, label_width - y
|
164
|
+
pdf.rectangle [x * pdf_dpi, label_width - (y * pdf_dpi) -
|
165
|
+
(width * pdf_dpi)], height,
|
166
|
+
(width * pdf_dpi) * -1
|
117
167
|
end
|
118
168
|
end
|
119
169
|
|
120
170
|
# Draws the PDF bar code 39
|
121
171
|
def draw_bar_code_39(bar_code_string, x, y, height)
|
122
172
|
return unless label_height > 0 && label_width > 0
|
123
|
-
pdf.bounding_box [x, Integer(label_width) - y - height],
|
124
|
-
width: height do
|
173
|
+
pdf.bounding_box [x, Integer(label_width) - y - (height * pdf_dpi)],
|
174
|
+
width: (height * pdf_dpi) do
|
125
175
|
barcode = Barby::Code39.new(bar_code_string)
|
126
|
-
barcode.annotate_pdf(pdf, height: height)
|
176
|
+
barcode.annotate_pdf(pdf, height: (height * pdf_dpi))
|
127
177
|
end
|
128
178
|
end
|
129
179
|
end
|
@@ -16,6 +16,13 @@ module Easyzpl
|
|
16
16
|
return if name.nil?
|
17
17
|
return if name.strip.empty?
|
18
18
|
|
19
|
+
# Set the DPIs
|
20
|
+
self.pdf_dpi = 72
|
21
|
+
self.printer_dpi = params[:dots]
|
22
|
+
|
23
|
+
# Set the field orientation
|
24
|
+
self.field_orientation = params[:field_orientation]
|
25
|
+
|
19
26
|
# Set the number of variable fields
|
20
27
|
self.variable_fields_count = 0
|
21
28
|
|
@@ -25,46 +32,107 @@ module Easyzpl
|
|
25
32
|
# Set the default quantity to one
|
26
33
|
self.quantity = 1
|
27
34
|
|
35
|
+
# See if invert is set to true
|
36
|
+
self.invert = params[:invert]
|
37
|
+
|
28
38
|
# The start of the label
|
29
|
-
label_data.push('^XA
|
39
|
+
label_data.push('^XA')
|
40
|
+
label_data.push('^POI') if invert
|
41
|
+
label_data.push('^LT' + Integer(params[:offset] * printer_dpi).to_s) unless params[:offset].nil?
|
42
|
+
label_data.push('^LL' + Integer(params[:height] * printer_dpi).to_s) unless params[:height].nil?
|
43
|
+
label_data.push('^PW' + Integer(params[:width] * printer_dpi).to_s) unless params[:width].nil?
|
44
|
+
label_data.push('^FWB') if field_orientation == :landscape
|
45
|
+
label_data.push('^DF' + name + '^FS')
|
30
46
|
|
31
|
-
init_prawn(params)
|
47
|
+
# init_prawn(params)
|
32
48
|
end
|
33
49
|
|
34
50
|
# Sets a variable field that can be recalled
|
35
51
|
def variable_text_field(x, y, params = {})
|
36
52
|
x = 0 unless numeric?(x)
|
37
53
|
y = 0 unless numeric?(y)
|
38
|
-
options = { height:
|
54
|
+
options = { height: 0.1, width: 0.1 }.merge!(params)
|
39
55
|
|
40
56
|
# update the variable field count
|
41
57
|
self.variable_fields_count += 1
|
42
58
|
|
43
|
-
label_data.push('^FO' + x
|
44
|
-
|
59
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
60
|
+
Integer(y * printer_dpi).to_s)
|
61
|
+
|
62
|
+
if params[:orientation] == :landscape
|
63
|
+
label_data.push('^AFB,')
|
64
|
+
else
|
65
|
+
label_data.push('^AFN,')
|
66
|
+
end
|
67
|
+
|
68
|
+
label_data.push(Integer(options[:height] * printer_dpi).to_s + ',' +
|
69
|
+
Integer(options[:width] * printer_dpi).to_s +
|
45
70
|
'^FN' + variable_fields_count.to_s + '^FS')
|
46
71
|
|
47
|
-
return unless label_height > 0 && label_width > 0
|
48
|
-
pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}',
|
49
|
-
|
50
|
-
|
72
|
+
# return unless label_height > 0 && label_width > 0
|
73
|
+
# pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}',
|
74
|
+
# at: [Integer(x * pdf_dpi), Integer(label_width * pdf_dpi) -
|
75
|
+
# Integer(y * pdf_dpi) -
|
76
|
+
# Integer(options[:height] / 10) * pdf_dpi],
|
77
|
+
# size: Integer(options[:height] * pdf_dpi) if label_height &&
|
78
|
+
# label_width
|
51
79
|
end
|
52
80
|
|
53
81
|
# Sets a variable bar code that can be recalled
|
54
82
|
def variable_bar_code_39(x, y, params = {})
|
55
83
|
x = 0 unless numeric?(x)
|
56
84
|
y = 0 unless numeric?(y)
|
85
|
+
options = { height: 0.1, width: 0.1 }.merge!(params)
|
57
86
|
|
58
87
|
# update the variable field count
|
59
88
|
self.variable_fields_count += 1
|
60
89
|
|
61
|
-
label_data.push('^FO' + x
|
62
|
-
|
90
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
91
|
+
Integer(y * printer_dpi).to_s)
|
92
|
+
label_data.push('^BY2,2,100')
|
93
|
+
|
94
|
+
if params[:orientation] == :landscape
|
95
|
+
label_data.push('^B3B,')
|
96
|
+
else
|
97
|
+
label_data.push('^B3N,')
|
98
|
+
end
|
99
|
+
|
100
|
+
label_data.push('Y,' + Integer(options[:height] * printer_dpi).to_s +
|
101
|
+
',N,N^FN' + variable_fields_count.to_s + '^FS')
|
102
|
+
|
103
|
+
# return unless label_height && label_width
|
104
|
+
# options = { height: 20 }.merge(params)
|
105
|
+
# draw_bar_code_39('VARIABLEFIELD' + variable_fields_count.to_s,
|
106
|
+
# Integer(x * pdf_dpi), Integer(y * pdf_dpi),
|
107
|
+
# Integer(options[:height] * pdf_dpi))
|
108
|
+
end
|
109
|
+
|
110
|
+
# This creates a PDF417 bar code, which is very common in the automotive
|
111
|
+
# industry. The format is as follows:
|
112
|
+
# ^B7o,h,s,c,r,t
|
113
|
+
# o = Orientation
|
114
|
+
# N - normal, R rotated 90 degrees clockwise, I inverted 180 degrees
|
115
|
+
# B - Read from bottom up 270 degrees
|
116
|
+
# h = height for individual rows in dots
|
117
|
+
def variable_bar_code_pdf417(x, y, params = {})
|
118
|
+
x = 0 unless numeric?(x)
|
119
|
+
y = 0 unless numeric?(y)
|
120
|
+
options = { height: 0.1, width: 0.1 }.merge!(params)
|
121
|
+
|
122
|
+
# update the variable field count
|
123
|
+
self.variable_fields_count += 1
|
124
|
+
|
125
|
+
label_data.push('^FO' + Integer(x * printer_dpi).to_s + ',' +
|
126
|
+
Integer(y * printer_dpi).to_s)
|
127
|
+
|
128
|
+
if params[:orientation] == :landscape
|
129
|
+
label_data.push('^B7B,')
|
130
|
+
else
|
131
|
+
label_data.push('^B7N,')
|
132
|
+
end
|
63
133
|
|
64
|
-
|
65
|
-
|
66
|
-
draw_bar_code_39('VARIABLEFIELD' + variable_fields_count.to_s,
|
67
|
-
x, y, options[:height])
|
134
|
+
label_data.push((printer_dpi / 5).to_s + ',0,' + 5.to_s + ',' + 8.to_s +
|
135
|
+
',N^FN' + variable_fields_count.to_s + '^FS')
|
68
136
|
end
|
69
137
|
end
|
70
138
|
end
|
data/lib/easyzpl/version.rb
CHANGED
data/spec/easyzpl_spec.rb
CHANGED
@@ -3,30 +3,30 @@ require 'spec_helper'
|
|
3
3
|
describe 'Testing easyzpl Gem' do
|
4
4
|
context 'When creating an empty label' do
|
5
5
|
it 'should output a blank label' do
|
6
|
-
label = Easyzpl::Label.new
|
6
|
+
label = Easyzpl::Label.new(dots: 203)
|
7
7
|
expect(label.to_s).to eq('^XA^PQ1^XZ')
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'When creating a simple lable' do
|
12
12
|
it 'should output a label with the text "Zebra" and a barcode representation' do
|
13
|
-
label = Easyzpl::Label.new
|
13
|
+
label = Easyzpl::Label.new(dots: 203)
|
14
14
|
label.home_position(30, 30)
|
15
15
|
label.draw_border(0, 0, 400, 300)
|
16
16
|
label.text_field('ZEBRA', 10, 10)
|
17
17
|
label.bar_code_39('ZEBRA', 10, 30)
|
18
|
-
expect(label.to_s).to eq('^XA^LH30,30^FO0,0^
|
18
|
+
expect(label.to_s).to eq('^XA^LH30,30^FO0,0^GB81200,60900,1^FS^FO2030,2030^AFN,20,20^FDZEBRA^FS^FO2030,6090^B3N,Y,20,N,N^FDZEBRA^FS^PQ1^XZ')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'When creating a stored template' do
|
23
23
|
it 'should output a label template with one variable text field and one variable barcode' do
|
24
|
-
label = Easyzpl::LabelTemplate.new('Template1')
|
24
|
+
label = Easyzpl::LabelTemplate.new('Template1', dots: 203)
|
25
25
|
label.home_position(30, 30)
|
26
26
|
label.draw_border(0, 0, 400, 300)
|
27
27
|
label.variable_text_field(10, 10)
|
28
28
|
label.variable_bar_code_39(10, 30)
|
29
|
-
expect(label.to_s).to eq('^XA^DFTemplate1^FS^LH30,30^FO0,0^
|
29
|
+
expect(label.to_s).to eq('^XA^DFTemplate1^FS^LH30,30^FO0,0^GB81200,60900,1^FS^FO2030,2030^AFN,20,20^FN1^FS^FO2030,6090^BY2,2,100^B3N,Y,20,N,N^FN2^FS^PQ1^XZ')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyzpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Grigajtis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|