zebra-zpl 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/docs/example.rb CHANGED
@@ -1,290 +1,290 @@
1
- require_relative '../lib/zebra/zpl'
2
-
3
- def print_zpl_str(name, label)
4
- zpl = ''
5
- label.dump_contents zpl
6
- puts "\n#{name}:\n#{zpl}\n\n"
7
- end
8
-
9
- def new_label
10
- Zebra::Zpl::Label.new(
11
- width: 600,
12
- length: 305,
13
- print_speed: 6,
14
- print_density: 5,
15
- copies: 1
16
- )
17
- end
18
-
19
- ################################################################################
20
- # Text
21
- ################################################################################
22
- label = new_label
23
- text = Zebra::Zpl::Text.new(
24
- data: "Hello, printer!",
25
- position: [10, 125],
26
- font_size: Zebra::Zpl::FontSize::SIZE_5,
27
- justification: Zebra::Zpl::Justification::CENTER
28
- )
29
- box = Zebra::Zpl::Graphic.new(
30
- graphic_type: 'B',
31
- position: [10,5],
32
- graphic_width: label.width,
33
- graphic_height: label.length-10,
34
- line_thickness: 1,
35
- rounding_degree: 1
36
- )
37
- label << text
38
- label << box
39
- print_zpl_str('text', label)
40
-
41
- ################################################################################
42
- # Raw ZPL
43
- ################################################################################
44
- label = new_label
45
- zpl_string = "^GFA,1300,1300,13,,::::::O01IFE,N01KFE,N0MFC,M03NF,M0OFC,L03PF,L0QF8,K01QFE,K03RF,K07RF8,J01SFC,J03F9OFE7E,J07F01MFE03F,J07E007LF803F8,J0FE003KFE001FC,I01FEI0FC00FC001FE,I03FCI04M01FF,I07FCQ01FF,I07FCQ01FF8,I0FFCQ01FFC,I0FFEQ01FFC,001FFEQ01FFE,:003FFEQ03IF,003FFEQ01IF,007FFCR0IF,007FFCR0IF8,007FF8R07FF8,00IFS03FF8,00IFS03FFC,:00FFES01FFC,01FFES01FFC,01FFES01FFE,:01FFCS01FFE,:::::01FFES01FFE,::01FFES03FFE,01IFS03FFE,01IFS03FFC,01IF8R07FFC,00IF8R0IFC,00IFCR0IFC,00IFEQ01IFC,00JFQ03IF8,007IF8P07IF8,007IFCP0JF8,007JFO03JF,003F87FCN0KF,003F81FFM03JFE,001F80FFEK01KFE,001FC07FFCJ0LFC,I0FF03FF8J0LFC,I0FF03FF8J07KF8,I07F81FF8J07KF8,I03F807F8J07KF,I03FC004K07JFE,I01FCN07JFE,J0FEN07JFC,J07FN07JF8,J03F8M07JF,J01FCM07IFE,K0FFM07IFC,K07IF8J07IF8,K03IF8J07IF,L0IF8J07FFC,L07FF8J07FF8,L01FF8J07FE,M0FF8J07F8,M01F8J07E,N07K038,,::::::::::::::^FS"
46
- raw_zpl = Zebra::Zpl::Raw.new(
47
- data: zpl_string,
48
- position: [50, 50],
49
- )
50
- label << raw_zpl
51
- print_zpl_str('raw_zpl', label)
52
-
53
- ################################################################################
54
- # Barcode
55
- ################################################################################
56
- label = new_label
57
- barcode = Zebra::Zpl::Barcode.new(
58
- data: 'F112358',
59
- position: [80, 50],
60
- height: 150,
61
- width: 4,
62
- print_human_readable_code: true,
63
- type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
64
- )
65
- label << barcode
66
- print_zpl_str('barcode', label)
67
-
68
- ################################################################################
69
- # QR Code
70
- ################################################################################
71
- label = new_label
72
- qrcode = Zebra::Zpl::Qrcode.new(
73
- data: 'www.github.com',
74
- position: [200, 45],
75
- scale_factor: 8,
76
- correction_level: 'H',
77
- )
78
- label << qrcode
79
- print_zpl_str('qrcode', label)
80
-
81
- ################################################################################
82
- # Data Matrix
83
- ################################################################################
84
- label = new_label
85
- datamatrix = Zebra::Zpl::Datamatrix.new(
86
- data: 'www.github.com',
87
- position: [225, 75],
88
- symbol_height: 10,
89
- aspect_ratio: 1
90
- )
91
- label << datamatrix
92
- print_zpl_str('datamatrix', label)
93
-
94
- ################################################################################
95
- # Graphics
96
- ################################################################################
97
- label = new_label
98
- box = Zebra::Zpl::Graphic.new(
99
- graphic_type: 'B',
100
- position: [10,10],
101
- graphic_width: 80,
102
- graphic_height: 80,
103
- line_thickness: 2,
104
- rounding_degree: 2
105
- )
106
- circle = Zebra::Zpl::Graphic.new(
107
- graphic_type: 'C',
108
- position: [100,10],
109
- graphic_width: 80,
110
- line_thickness: 3
111
- )
112
- diagonal1 = Zebra::Zpl::Graphic.new(
113
- graphic_type: 'D',
114
- position: [190,10],
115
- graphic_width: 80,
116
- graphic_height: 80,
117
- line_thickness: 3,
118
- orientation: 'R'
119
- )
120
- diagonal2 = diagonal1.dup
121
- diagonal2.orientation = 'L'
122
- ellipse = Zebra::Zpl::Graphic.new(
123
- graphic_type: 'E',
124
- position: [280,10],
125
- graphic_width: 40,
126
- graphic_height: 80,
127
- line_thickness: 3
128
- )
129
- symbol = Zebra::Zpl::Graphic.new(
130
- graphic_type: 'S',
131
- symbol_type: 'B',
132
- position: [335,10],
133
- graphic_width: 80,
134
- graphic_height: 80
135
- )
136
-
137
- label << box
138
- label << circle
139
- label << diagonal1
140
- label << diagonal2
141
- label << ellipse
142
- label << symbol
143
- label.elements.each { |e| e.position = [e.x + 110 , e.y + 90] }
144
- print_zpl_str('graphics', label)
145
-
146
- ################################################################################
147
- # Images
148
- ################################################################################
149
- label = new_label
150
- image = Zebra::Zpl::Image.new(
151
- path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
152
- position: [145, 0],
153
- width: 305,
154
- height: 305
155
- )
156
- label << image
157
- print_zpl_str('image', label)
158
-
159
- # inverted image
160
- label = new_label
161
- image = Zebra::Zpl::Image.new(
162
- path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
163
- position: [145, 0],
164
- width: 305,
165
- height: 305,
166
- invert: true
167
- )
168
- label << image
169
- print_zpl_str('image_inverted', label)
170
-
171
- ################################################################################
172
- # Image Manipulation
173
- ################################################################################
174
- label = new_label
175
- image = Zebra::Zpl::Image.new(
176
- path: File.expand_path('./images/ruby.png', File.dirname(__FILE__)),
177
- position: [0, 0],
178
- width: 305,
179
- height: 305,
180
- black_threshold: 0.65
181
- )
182
- src = image.source
183
- src.background('white').flatten
184
-
185
- # perform edge detection on the image
186
- MiniMagick::Tool::Convert.new do |convert|
187
- convert << src.path
188
- convert << '-colorspace' << 'gray'
189
- convert << '-edge' << '4'
190
- convert << '-negate'
191
- convert << src.path
192
- end
193
-
194
- src.trim
195
-
196
- label << image
197
- print_zpl_str('image_manipulation', label)
198
-
199
- ################################################################################
200
- # Justification
201
- ################################################################################
202
- label = new_label
203
- t1 = Zebra::Zpl::Text.new(
204
- data: "ZPL",
205
- position: [10, 25],
206
- font_size: Zebra::Zpl::FontSize::SIZE_5,
207
- justification: Zebra::Zpl::Justification::LEFT
208
- )
209
- t2 = Zebra::Zpl::Text.new(
210
- data: "ZPL",
211
- position: [10, 65],
212
- font_size: Zebra::Zpl::FontSize::SIZE_5,
213
- justification: Zebra::Zpl::Justification::CENTER
214
- )
215
- t3 = Zebra::Zpl::Text.new(
216
- data: "ZPL",
217
- position: [10, 105],
218
- font_size: Zebra::Zpl::FontSize::SIZE_5,
219
- justification: Zebra::Zpl::Justification::RIGHT
220
- )
221
- t4 = Zebra::Zpl::Text.new(
222
- data: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
223
- position: [10, 180],
224
- font_size: Zebra::Zpl::FontSize::SIZE_4,
225
- justification: Zebra::Zpl::Justification::JUSTIFIED
226
- )
227
- box = Zebra::Zpl::Graphic.new(
228
- graphic_type: 'B',
229
- position: [10,5],
230
- graphic_width: label.width,
231
- graphic_height: label.length-10,
232
- line_thickness: 1,
233
- rounding_degree: 1
234
- )
235
- label << t1
236
- label << t2
237
- label << t3
238
- label << t4
239
- label << box
240
- print_zpl_str('justification', label)
241
-
242
- ################################################################################
243
- # Rotation
244
- ################################################################################
245
- label = new_label
246
- t1 = Zebra::Zpl::Text.new(
247
- data: "Zero",
248
- position: [10, 125],
249
- font_size: Zebra::Zpl::FontSize::SIZE_5,
250
- rotation: Zebra::Zpl::Rotation::NO_ROTATION,
251
- max_lines: 1
252
- )
253
- t2 = Zebra::Zpl::Text.new(
254
- data: "90",
255
- position: [100, 125],
256
- font_size: Zebra::Zpl::FontSize::SIZE_5,
257
- rotation: Zebra::Zpl::Rotation::DEGREES_90,
258
- max_lines: 1
259
- )
260
- t3 = Zebra::Zpl::Text.new(
261
- data: "180",
262
- position: [175, 125],
263
- font_size: Zebra::Zpl::FontSize::SIZE_5,
264
- rotation: Zebra::Zpl::Rotation::DEGREES_180,
265
- justification: Zebra::Zpl::Justification::RIGHT,
266
- max_lines: 1
267
- )
268
- t4 = Zebra::Zpl::Text.new(
269
- data: "270",
270
- position: [275, 125],
271
- font_size: Zebra::Zpl::FontSize::SIZE_5,
272
- rotation: Zebra::Zpl::Rotation::DEGREES_270,
273
- justification: Zebra::Zpl::Justification::RIGHT,
274
- max_lines: 1
275
- )
276
- box = Zebra::Zpl::Graphic.new(
277
- graphic_type: 'B',
278
- position: [10,5],
279
- graphic_width: label.width,
280
- graphic_height: label.length-10,
281
- line_thickness: 1,
282
- rounding_degree: 1
283
- )
284
- label << t1
285
- label << t2
286
- label << t3
287
- label << t4
288
- label.elements.each { |e| e.position = [e.x + 150, e.y] }
289
- label << box
290
- print_zpl_str('rotation', label)
1
+ require_relative '../lib/zebra/zpl'
2
+
3
+ def print_zpl_str(name, label)
4
+ zpl = ''
5
+ label.dump_contents zpl
6
+ puts "\n#{name}:\n#{zpl}\n\n"
7
+ end
8
+
9
+ def new_label
10
+ Zebra::Zpl::Label.new(
11
+ width: 600,
12
+ length: 305,
13
+ print_speed: 6,
14
+ print_density: 5,
15
+ copies: 1
16
+ )
17
+ end
18
+
19
+ ################################################################################
20
+ # Text
21
+ ################################################################################
22
+ label = new_label
23
+ text = Zebra::Zpl::Text.new(
24
+ data: "Hello, printer!",
25
+ position: [10, 125],
26
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
27
+ justification: Zebra::Zpl::Justification::CENTER
28
+ )
29
+ box = Zebra::Zpl::Graphic.new(
30
+ graphic_type: 'B',
31
+ position: [10,5],
32
+ graphic_width: label.width,
33
+ graphic_height: label.length-10,
34
+ line_thickness: 1,
35
+ rounding_degree: 1
36
+ )
37
+ label << text
38
+ label << box
39
+ print_zpl_str('text', label)
40
+
41
+ ################################################################################
42
+ # Raw ZPL
43
+ ################################################################################
44
+ label = new_label
45
+ zpl_string = "^GFA,1300,1300,13,,::::::O01IFE,N01KFE,N0MFC,M03NF,M0OFC,L03PF,L0QF8,K01QFE,K03RF,K07RF8,J01SFC,J03F9OFE7E,J07F01MFE03F,J07E007LF803F8,J0FE003KFE001FC,I01FEI0FC00FC001FE,I03FCI04M01FF,I07FCQ01FF,I07FCQ01FF8,I0FFCQ01FFC,I0FFEQ01FFC,001FFEQ01FFE,:003FFEQ03IF,003FFEQ01IF,007FFCR0IF,007FFCR0IF8,007FF8R07FF8,00IFS03FF8,00IFS03FFC,:00FFES01FFC,01FFES01FFC,01FFES01FFE,:01FFCS01FFE,:::::01FFES01FFE,::01FFES03FFE,01IFS03FFE,01IFS03FFC,01IF8R07FFC,00IF8R0IFC,00IFCR0IFC,00IFEQ01IFC,00JFQ03IF8,007IF8P07IF8,007IFCP0JF8,007JFO03JF,003F87FCN0KF,003F81FFM03JFE,001F80FFEK01KFE,001FC07FFCJ0LFC,I0FF03FF8J0LFC,I0FF03FF8J07KF8,I07F81FF8J07KF8,I03F807F8J07KF,I03FC004K07JFE,I01FCN07JFE,J0FEN07JFC,J07FN07JF8,J03F8M07JF,J01FCM07IFE,K0FFM07IFC,K07IF8J07IF8,K03IF8J07IF,L0IF8J07FFC,L07FF8J07FF8,L01FF8J07FE,M0FF8J07F8,M01F8J07E,N07K038,,::::::::::::::^FS"
46
+ raw_zpl = Zebra::Zpl::Raw.new(
47
+ data: zpl_string,
48
+ position: [50, 50],
49
+ )
50
+ label << raw_zpl
51
+ print_zpl_str('raw_zpl', label)
52
+
53
+ ################################################################################
54
+ # Barcode
55
+ ################################################################################
56
+ label = new_label
57
+ barcode = Zebra::Zpl::Barcode.new(
58
+ data: 'F112358',
59
+ position: [80, 50],
60
+ height: 150,
61
+ width: 4,
62
+ print_human_readable_code: true,
63
+ type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
64
+ )
65
+ label << barcode
66
+ print_zpl_str('barcode', label)
67
+
68
+ ################################################################################
69
+ # QR Code
70
+ ################################################################################
71
+ label = new_label
72
+ qrcode = Zebra::Zpl::Qrcode.new(
73
+ data: 'www.github.com',
74
+ position: [200, 45],
75
+ scale_factor: 8,
76
+ correction_level: 'H',
77
+ )
78
+ label << qrcode
79
+ print_zpl_str('qrcode', label)
80
+
81
+ ################################################################################
82
+ # Data Matrix
83
+ ################################################################################
84
+ label = new_label
85
+ datamatrix = Zebra::Zpl::Datamatrix.new(
86
+ data: 'www.github.com',
87
+ position: [225, 75],
88
+ symbol_height: 10,
89
+ aspect_ratio: 1
90
+ )
91
+ label << datamatrix
92
+ print_zpl_str('datamatrix', label)
93
+
94
+ ################################################################################
95
+ # Graphics
96
+ ################################################################################
97
+ label = new_label
98
+ box = Zebra::Zpl::Graphic.new(
99
+ graphic_type: 'B',
100
+ position: [10,10],
101
+ graphic_width: 80,
102
+ graphic_height: 80,
103
+ line_thickness: 2,
104
+ rounding_degree: 2
105
+ )
106
+ circle = Zebra::Zpl::Graphic.new(
107
+ graphic_type: 'C',
108
+ position: [100,10],
109
+ graphic_width: 80,
110
+ line_thickness: 3
111
+ )
112
+ diagonal1 = Zebra::Zpl::Graphic.new(
113
+ graphic_type: 'D',
114
+ position: [190,10],
115
+ graphic_width: 80,
116
+ graphic_height: 80,
117
+ line_thickness: 3,
118
+ orientation: 'R'
119
+ )
120
+ diagonal2 = diagonal1.dup
121
+ diagonal2.orientation = 'L'
122
+ ellipse = Zebra::Zpl::Graphic.new(
123
+ graphic_type: 'E',
124
+ position: [280,10],
125
+ graphic_width: 40,
126
+ graphic_height: 80,
127
+ line_thickness: 3
128
+ )
129
+ symbol = Zebra::Zpl::Graphic.new(
130
+ graphic_type: 'S',
131
+ symbol_type: 'B',
132
+ position: [335,10],
133
+ graphic_width: 80,
134
+ graphic_height: 80
135
+ )
136
+
137
+ label << box
138
+ label << circle
139
+ label << diagonal1
140
+ label << diagonal2
141
+ label << ellipse
142
+ label << symbol
143
+ label.elements.each { |e| e.position = [e.x + 110 , e.y + 90] }
144
+ print_zpl_str('graphics', label)
145
+
146
+ ################################################################################
147
+ # Images
148
+ ################################################################################
149
+ label = new_label
150
+ image = Zebra::Zpl::Image.new(
151
+ path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
152
+ position: [145, 0],
153
+ width: 305,
154
+ height: 305
155
+ )
156
+ label << image
157
+ print_zpl_str('image', label)
158
+
159
+ # inverted image
160
+ label = new_label
161
+ image = Zebra::Zpl::Image.new(
162
+ path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
163
+ position: [145, 0],
164
+ width: 305,
165
+ height: 305,
166
+ invert: true
167
+ )
168
+ label << image
169
+ print_zpl_str('image_inverted', label)
170
+
171
+ ################################################################################
172
+ # Image Manipulation
173
+ ################################################################################
174
+ label = new_label
175
+ image = Zebra::Zpl::Image.new(
176
+ path: File.expand_path('./images/ruby.png', File.dirname(__FILE__)),
177
+ position: [0, 0],
178
+ width: 305,
179
+ height: 305,
180
+ black_threshold: 0.65
181
+ )
182
+ src = image.source
183
+ src.background('white').flatten
184
+
185
+ # perform edge detection on the image
186
+ MiniMagick::Tool::Convert.new do |convert|
187
+ convert << src.path
188
+ convert << '-colorspace' << 'gray'
189
+ convert << '-edge' << '4'
190
+ convert << '-negate'
191
+ convert << src.path
192
+ end
193
+
194
+ src.trim
195
+
196
+ label << image
197
+ print_zpl_str('image_manipulation', label)
198
+
199
+ ################################################################################
200
+ # Justification
201
+ ################################################################################
202
+ label = new_label
203
+ t1 = Zebra::Zpl::Text.new(
204
+ data: "ZPL",
205
+ position: [10, 25],
206
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
207
+ justification: Zebra::Zpl::Justification::LEFT
208
+ )
209
+ t2 = Zebra::Zpl::Text.new(
210
+ data: "ZPL",
211
+ position: [10, 65],
212
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
213
+ justification: Zebra::Zpl::Justification::CENTER
214
+ )
215
+ t3 = Zebra::Zpl::Text.new(
216
+ data: "ZPL",
217
+ position: [10, 105],
218
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
219
+ justification: Zebra::Zpl::Justification::RIGHT
220
+ )
221
+ t4 = Zebra::Zpl::Text.new(
222
+ data: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
223
+ position: [10, 180],
224
+ font_size: Zebra::Zpl::FontSize::SIZE_4,
225
+ justification: Zebra::Zpl::Justification::JUSTIFIED
226
+ )
227
+ box = Zebra::Zpl::Graphic.new(
228
+ graphic_type: 'B',
229
+ position: [10,5],
230
+ graphic_width: label.width,
231
+ graphic_height: label.length-10,
232
+ line_thickness: 1,
233
+ rounding_degree: 1
234
+ )
235
+ label << t1
236
+ label << t2
237
+ label << t3
238
+ label << t4
239
+ label << box
240
+ print_zpl_str('justification', label)
241
+
242
+ ################################################################################
243
+ # Rotation
244
+ ################################################################################
245
+ label = new_label
246
+ t1 = Zebra::Zpl::Text.new(
247
+ data: "Zero",
248
+ position: [10, 125],
249
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
250
+ rotation: Zebra::Zpl::Rotation::NO_ROTATION,
251
+ max_lines: 1
252
+ )
253
+ t2 = Zebra::Zpl::Text.new(
254
+ data: "90",
255
+ position: [100, 125],
256
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
257
+ rotation: Zebra::Zpl::Rotation::DEGREES_90,
258
+ max_lines: 1
259
+ )
260
+ t3 = Zebra::Zpl::Text.new(
261
+ data: "180",
262
+ position: [175, 125],
263
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
264
+ rotation: Zebra::Zpl::Rotation::DEGREES_180,
265
+ justification: Zebra::Zpl::Justification::RIGHT,
266
+ max_lines: 1
267
+ )
268
+ t4 = Zebra::Zpl::Text.new(
269
+ data: "270",
270
+ position: [275, 125],
271
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
272
+ rotation: Zebra::Zpl::Rotation::DEGREES_270,
273
+ justification: Zebra::Zpl::Justification::RIGHT,
274
+ max_lines: 1
275
+ )
276
+ box = Zebra::Zpl::Graphic.new(
277
+ graphic_type: 'B',
278
+ position: [10,5],
279
+ graphic_width: label.width,
280
+ graphic_height: label.length-10,
281
+ line_thickness: 1,
282
+ rounding_degree: 1
283
+ )
284
+ label << t1
285
+ label << t2
286
+ label << t3
287
+ label << t4
288
+ label.elements.each { |e| e.position = [e.x + 150, e.y] }
289
+ label << box
290
+ print_zpl_str('rotation', label)