zebra-zpl 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,418 +1,442 @@
1
- # Zebra::Zpl
2
-
3
- [![gem](https://img.shields.io/gem/v/zebra-zpl?color=orange)](https://rubygems.org/gems/zebra-zpl)
4
- [![downloads](https://img.shields.io/gem/dt/zebra-zpl?color=brightgreen)](https://rubygems.org/gems/zebra-zpl)
5
-
6
- Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
7
-
8
- ## Contents
9
-
10
- - [Installation](#installation)
11
- - [Usage](#usage)
12
- - [Building Labels](#building-labels)
13
- - [Printing Labels](#printing-the-labels)
14
- - [Elements](#available-elements)
15
- - [Text](#text)
16
- - [Barcodes](#barcodes)
17
- - [QR Codes](#qr-codes)
18
- - [Data Matrix](#data-matrix)
19
- - ~[Boxes](#boxes)~ - deprecated. See [Graphics](#graphics)
20
- - [Images](#images)
21
- - [Options](#options)
22
- - [Rotation](#elements-rotation)
23
- - [Justification](#elements-justification)
24
- - [Contributing](#contributing)
25
- - [References](#references)
26
-
27
-
28
- ## Installation
29
-
30
- Add this line to your application's Gemfile:
31
-
32
- gem 'zebra-zpl'
33
-
34
- And then execute:
35
-
36
- bundle install
37
-
38
- Or install it yourself as:
39
-
40
- gem install zebra-zpl
41
-
42
- ## Usage
43
-
44
- ### Building labels
45
-
46
- You create new labels with an instance of the `Zebra::Zpl::Label` class. It accepts the following options:
47
-
48
- * `copies`: The number of copies to print. This option defaults to 1.
49
- * `width`: The label's width, in dots.
50
- * `length`: The label's length, is dots.
51
- * `print_speed`: The print speed to be used. You can use values between 0 and 6. This option is required.
52
-
53
- With a label, you can start adding elements to it:
54
-
55
- ```ruby
56
- label = Zebra::Zpl::Label.new print_speed: 3
57
- text = Zebra::Zpl::Text.new(
58
- data: "Hello, printer!",
59
- position: [100, 100],
60
- font_size: Zebra::Zpl::FontSize::SIZE_2
61
- )
62
- label << text
63
- ```
64
-
65
- You can add as many elements as you want.
66
-
67
- ### Printing the labels
68
-
69
- You need to have your printer visible to CUPS (or shared on the network in Windows). Once your printer is configured and you know its name on CUPS (or the Windows shared printer name), you can send the labels to the printer using a `Zebra::PrintJob` instance.
70
-
71
- ```ruby
72
- label = Zebra::Zpl::Label.new(
73
- width: 200,
74
- length: 200,
75
- print_speed: 3
76
- )
77
-
78
-
79
- barcode = Zebra::Zpl::Barcode.new(
80
- data: '12345678',
81
- position: [50, 50],
82
- height: 50,
83
- print_human_readable_code: true,
84
- narrow_bar_width: 4,
85
- wide_bar_width: 8,
86
- type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
87
- )
88
-
89
- label << barcode
90
-
91
- print_job = Zebra::PrintJob.new '<your-printer-name-on-cups/windows-shared-printer-name>'
92
-
93
- ip = '<IP/Host where the print queue lives>' # can use 'localhost', '127.0.0.1', or '0.0.0.0' for local machine
94
-
95
- print_job.print label, ip
96
- ```
97
-
98
- This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `rlpr -H <hostname/ip> -P <your-printer-name-on-windows> -o <path-to-the-temp-file>` (for Windows systems, see [section](#printing-directly-to-windows-lpd) below) or `lp -h <hostname/ip> -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (for Unix systems). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
99
-
100
- ##### Print Service
101
-
102
- You can specify what print service command you want to be used when calling the `print` method by setting the `:print_service` option parameter. If left unspecified, it will attempt to send the print job first via `rlpr` - if the `rlpr` command fails in anyway then it will fall back to the `lp` command.
103
-
104
- ```ruby
105
- print_job.print label, ip, print_service: 'lp' # attempt only via the lp command
106
-
107
- print_job.print label, ip, print_service: 'rlpr' # attempt only via the rlpr command
108
-
109
- print_job.print label, ip # attempt via rlpr first, fallback to lp
110
- ```
111
-
112
- #### Printing directly to Windows LPD
113
- This gem also supports printing directly to shared printer on Windows using LPD.
114
- In order to print directly to a LPD on a Windows machine you need two things:
115
- - [rlpr](http://manpages.ubuntu.com/manpages/xenial/man1/rlpr.1.html) installed on the (UNIX) system running your app that uses this gem.<sup>[1](#fn1)</sup>
116
- - LPD Print Service and LPR Port Monitor features enabled on the Windows machine.<sup>[2](#fn2)</sup>
117
-
118
- <p align="center">
119
- <img align="center" src="http://i.imgur.com/3CWkEWU.png" height="300px"/>
120
- <p/>
121
-
122
- <hr/>
123
-
124
- <sup><a name="fn1">1</a>. On a distro such as Ubuntu simply do: `sudo apt-get install rlpr`
125
- If using OSX then you will have to manually build it from source and add it to your `$PATH` environment variable.<sup/>
126
-
127
- <sup><a name="fn2">2</a>. The printer name that you pass in must correspond with the **shared printer name** on the Windows machine.</sup>
128
-
129
- ## Available elements
130
-
131
- ### Text
132
-
133
- <p align="center">
134
- <img src="docs/images/text.png" width="400">
135
- </p>
136
-
137
- You create text elements to print using instances of the `Zebra::Zpl::Text` class. It accepts the following options:
138
-
139
- * `position`: An array with the coordinates to place the text, in dots.
140
- * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
141
- * `data`: The text to be printed.
142
- * `print_mode`: The print mode. Can be normal ("N") or reverse ("R").
143
- * `font_size`: The font size to use. You can use values between 1 and 5.
144
-
145
- For the print modes, you can also use the constants:
146
-
147
- * `Zebra::Zpl::PrintMode::NORMAL`
148
- * `Zebra::Zpl::PrintMode::REVERSE`
149
-
150
-
151
- ### Barcodes
152
-
153
- <p align="center">
154
- <img src="docs/images/barcode.png" width="400">
155
- </p>
156
-
157
- You create barcode elements to print using instances of the `Zebra::Zpl::Barcode` class. It accepts the following options:
158
-
159
- * `position`: An array with the coordinates to place the barcode, in dots.
160
- * `height`: The barcode's height, in dots.
161
- * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
162
- * `data`: The text to be printed.
163
- * `type`: The type os barcode to use. More on the available types below.
164
- * `narrow_bar_width`: The barcode's narrow bar width, in dots.
165
- * `wide_bar_width`: The barcode's wide bar width, in dots.
166
- * `print_human_readable_code`: Can be `true` or `false`, indicates if the human readable contents should be printed below the barcode.
167
-
168
- The available barcode types are:
169
-
170
- * `Zebra::Zpl::BarcodeType::CODE_39`
171
- * `Zebra::Zpl::BarcodeType::CODE_93`
172
- * `Zebra::Zpl::BarcodeType::CODE_128_AUTO`
173
- * `Zebra::Zpl::BarcodeType::CODABAR`
174
- * `Zebra::Zpl::BarcodeType::CODE_AZTEC`
175
- * `Zebra::Zpl::BarcodeType::CODE_AZTEC_PARAMS`
176
- * `Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE`
177
- * `Zebra::Zpl::BarcodeType::CODE_QR`
178
-
179
- ### QR Codes
180
-
181
- <p align="center">
182
- <img src="docs/images/qrcode.png" width="400">
183
- </p>
184
-
185
- You can create QR Codes elements to print using instances of the `Zebra::Zpl::Qrcode` class. It accepts the following options:
186
-
187
- * `position`: An array with the coordinates to place the QR code, in dots.
188
- * `scale_factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
189
- * `correction_level`: Algorithm enables reading damaged QR codes. There are four error correction levels: L - 7% of codewords can be restored, M - 15% can be restored, Q - 25% can be restored, H - 30% can be restored.
190
-
191
- #### Printing QR codes
192
-
193
- ```ruby
194
- label = Zebra::Zpl::Label.new(
195
- width: 350,
196
- length: 250,
197
- print_speed: 3
198
- )
199
-
200
- qrcode = Zebra::Zpl::Qrcode.new(
201
- data: 'www.github.com',
202
- position: [50,10],
203
- scale_factor: 3,
204
- correction_level: 'H'
205
- )
206
-
207
- label << qrcode
208
-
209
- print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
210
-
211
- print_job.print label, '<hostname>'
212
- ```
213
-
214
- ### Data Matrix
215
-
216
- <p align="center">
217
- <img src="docs/images/datamatrix.png" width="400">
218
- </p>
219
-
220
- You can create Data Matrix elements to print using instances of the `Zebra::Zpl::Datamatrix` class. It accepts the following options:
221
-
222
- * `position`: An array with the coordinates to place the data matrix, in dots.
223
- * `symbol_height`: Crucial variable of the size size of the data matrix. Accepted values: 1 - label width.
224
- * `aspect_ratio`: 1 for square, 2 for rectangular.
225
-
226
- ```ruby
227
- datamatrix = Zebra::Zpl::Datamatrix.new(
228
- data: 'www.github.com',
229
- position: [50,50],
230
- symbol_height: 5
231
- )
232
- ```
233
-
234
- ### Boxes
235
-
236
- **&ast;&ast;&ast; The `Zebra::Zpl::Box` class is deprecated and will be removed in future versions. Please switch to the `Zebra::Zpl::Graphic` class (see [Graphics](#graphics) below). &ast;&ast;&ast;**
237
-
238
- ### Graphics
239
-
240
- <p align="center">
241
- <img src="docs/images/graphics.png" width="400">
242
- </p>
243
-
244
- You can create graphics elements using the `Zebra::Zpl::Graphic` class:
245
-
246
- * `position`: An array with the coordinates to place the graphic, in dots.
247
- * `graphic_type`: Sets the type of graphic:
248
- * `B`: Box
249
- * `C`: Circle
250
- * `D`: Diagonal
251
- * `E`: Ellipse
252
- * `S`: Symbol, _see symbol types below._
253
- * `graphic_width`: Width of the element in dots. (use as the diameter for circles, `C`)
254
- * `graphic_height`: Height of the element in dots. (does not apply to circles, `C`)
255
- * `line_thickness`: The thickness of the border in dots.
256
- * `color`: The color if the lines. B for black, W for white.
257
- * `orientation`: Only applies to diagonals (graphic type `D`). `R` for right-leaning. `L` for left-leaning.
258
- * `rounding_degree`: Only applies to boxes (graphic type `B`). Determines what degree to round the corners of the box. Valid values are 0 - 8.
259
- * `symbol_type`: Only applies to symbols (graphic type `S`). Possible values are:
260
- * `A`: ® - Registered Trade Mark
261
- * `B`: © - Copyright
262
- * `C`: ™ - Trade Mark
263
- * `D`: (UL) - Underwriters Laboratories approval
264
- * `E`: (SA) - Canadian Standards Association approval
265
-
266
- ```ruby
267
- label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
268
-
269
- box = Zebra::Zpl::Graphic.new(
270
- graphic_type: 'B',
271
- position: [20,25],
272
- graphic_width: 50,
273
- graphic_height: 50,
274
- line_thickness: 2,
275
- rounding_degree: 2
276
- )
277
-
278
- circle = Zebra::Zpl::Graphic.new(
279
- graphic_type: 'C',
280
- position: [80,25],
281
- graphic_width: 50,
282
- line_thickness: 3
283
- )
284
-
285
- diagonal1 = Zebra::Zpl::Graphic.new(
286
- graphic_type: 'D',
287
- position: [140,25],
288
- graphic_width: 50,
289
- graphic_height: 50,
290
- line_thickness: 3,
291
- orientation: 'R'
292
- )
293
- diagonal2 = diagonal1.dup
294
- diagonal2.orientation = 'L'
295
-
296
- ellipse = Zebra::Zpl::Graphic.new(
297
- graphic_type: 'E',
298
- position: [200,25],
299
- graphic_width: 25,
300
- graphic_height: 50,
301
- line_thickness: 3
302
- )
303
-
304
- symbol = Zebra::Zpl::Graphic.new(
305
- graphic_type: 'S',
306
- symbol_type: 'B',
307
- position: [235,25],
308
- graphic_width: 50,
309
- graphic_height: 50
310
- )
311
-
312
- label << box
313
- label << circle
314
- label << diagonal1
315
- label << diagonal2
316
- label << ellipse
317
- label << symbol
318
-
319
- print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
320
- print_job.print label, '<hostname>'
321
- ```
322
-
323
- ### Images
324
-
325
- <p align="center">
326
- <img src="docs/images/images.png" width="700">
327
- </p>
328
-
329
- You can also create graphics elements from an image using the `Zebra::Zpl::Image` class. Images are converted and encoded into an `^GF` (_Graphics Field_) command using the [img2zpl](https://github.com/mtking2/img2zpl) gem. Accepted parameters are:
330
-
331
- * `path` (required): The file path or URL of an image.
332
- * `position`: An array with the coordinates to place the image, in dots.
333
- * `width`: The width (in pixels) that the image should be printed.
334
- * `height`: The height (in pixels) that the image should be printed.
335
- * `rotation`: The number of degrees the image should be rotated
336
- * unlike the other elements with strict 90° rotations, image elements can be rotated any number of degrees since the image is rotated with imagemagick before conversion to ZPL.
337
- * `black_threshold`: A value between 0 and 1 that sets the darkness threshold which determines how dark a pixel should be in order to become black in the resulting b/w image. Use larger value for a more saturated image and smaller value for a less saturated one. Default: `0.5`
338
- * `invert`: set to `true` to invert which pixels are set to black and which are set to white. Default is, depending on the `black_threshold`, dark pixels become black and light pixels become white.
339
-
340
- #### Usage
341
- ```ruby
342
- label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
343
-
344
- image = Zebra::Zpl::Image.new(
345
- path: '/path/to/my/image.jpg',
346
- position: [100, 50],
347
- width: 200,
348
- height: 180,
349
- rotation: -90,
350
- black_threshold: 0.35
351
- )
352
-
353
- label << image
354
- ```
355
- **Modifying Images**
356
-
357
- <p align="center">
358
- <img src="docs/images/image_manipulation.png" width="500">
359
- </p>
360
-
361
- Image elements can also be modified in many ways before being added to the label by calling ImageMagick commands (provided by the [minimagick](https://github.com/minimagick/minimagick) & [img2zpl](https://github.com/mtking2/img2zpl) gems) on the source `Img2Zpl::Image < MiniMagick::Image` object.
362
-
363
- **Example:** Flattening an image's layers, so it is properly converted, and then trimming out unnecessary white space around the edges:
364
-
365
- ```ruby
366
- label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
367
- image = Zebra::Zpl::Image.new path: 'path/to/image.png', position: [0, 0]
368
-
369
- img_src = image.source #=> instance of Img2Zpl::Image < MiniMagick::Image
370
-
371
- img_src.flatten
372
- img_src.trim
373
-
374
- label << image
375
- ```
376
-
377
- ## Options
378
-
379
- ### Elements Rotation
380
-
381
- <p align="center">
382
- <img src="docs/images/rotation.png" width="400">
383
- </p>
384
-
385
- All printable elements can be rotated on the label, using the `:Rotation` option. The accepted rotation values are:
386
-
387
- * `Zebra::Zpl::Rotation::NO_ROTATION`: will not rotate the element.
388
- * `Zebra::Zpl::Rotation::DEGREES_90`: will rotate the element 90 degrees.
389
- * `Zebra::Zpl::Rotation::DEGREES_180`: will rotate the element 180 degrees.
390
- * `Zebra::Zpl::Rotation::DEGREES_270`: will rotate the element 270 degrees.
391
-
392
- ### Elements Justification
393
-
394
- <p align="center">
395
- <img src="docs/images/justification.png" width="400">
396
- </p>
397
-
398
- There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified) is the default.
399
-
400
- * `Zebra::Zpl::Justification::LEFT` ~ left-justified
401
- * `Zebra::Zpl::Justification::RIGHT` ~ right-justified
402
- * `Zebra::Zpl::Justification::CENTER` ~ centered
403
- * `Zebra::Zpl::Justification::JUSTIFIED` ~ full-width-justifed _(YMMV)_
404
-
405
- ## Examples
406
-
407
- See [docs/example.rb](docs/example.rb) for code samples of most elements.
408
-
409
- ## Contributing
410
-
411
- See [CONTRIBUTING.md](CONTRIBUTING.md) on how to contribute to this project.
412
-
413
- See [CHANGELOG.md](CHANGELOG.md) for a list of changes by version as well as all the awesome people who have contributed to the project.
414
-
415
- ## References
416
-
417
- ###### This is a gem based on a terrific older gem by Cassio Marques. Although the new printers are mostly compatible with old Eltron (Epl) code, our needs require many of the new Zebra (ZPL) functions.
418
- * [Zebra Technologies Corporation, _"ZPL II Programming Guide."_ 2019 PDF](https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf)
1
+ # Zebra::Zpl
2
+
3
+ [![gem](https://img.shields.io/gem/v/zebra-zpl?color=orange)](https://rubygems.org/gems/zebra-zpl)
4
+ [![downloads](https://img.shields.io/gem/dt/zebra-zpl?color=brightgreen)](https://rubygems.org/gems/zebra-zpl)
5
+
6
+ Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
7
+
8
+ ## Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Building Labels](#building-labels)
13
+ - [Printing Labels](#printing-the-labels)
14
+ - [Elements](#available-elements)
15
+ - [Text](#text)
16
+ - [Raw ZPL](#raw-zpl)
17
+ - [Barcodes](#barcodes)
18
+ - [QR Codes](#qr-codes)
19
+ - [Data Matrix](#data-matrix)
20
+ - ~[Boxes](#boxes)~ - deprecated. See [Graphics](#graphics)
21
+ - [Images](#images)
22
+ - [Options](#options)
23
+ - [Rotation](#elements-rotation)
24
+ - [Justification](#elements-justification)
25
+ - [Contributing](#contributing)
26
+ - [References](#references)
27
+
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ gem 'zebra-zpl'
34
+
35
+ And then execute:
36
+
37
+ bundle install
38
+
39
+ Or install it yourself as:
40
+
41
+ gem install zebra-zpl
42
+
43
+ ## Usage
44
+
45
+ ### Building labels
46
+
47
+ You create new labels with an instance of the `Zebra::Zpl::Label` class. It accepts the following options:
48
+
49
+ * `copies`: The number of copies to print. This option defaults to 1.
50
+ * `width`: The label's width, in dots.
51
+ * `length`: The label's length, is dots.
52
+ * `print_speed`: The print speed to be used. You can use values between 0 and 6. This option is required.
53
+ * `label_shift`: The label's shift is used to shift all field positions to the left. This option defaults to 10.
54
+
55
+ With a label, you can start adding elements to it:
56
+
57
+ ```ruby
58
+ label = Zebra::Zpl::Label.new print_speed: 3
59
+ text = Zebra::Zpl::Text.new(
60
+ data: "Hello, printer!",
61
+ position: [100, 100],
62
+ font_size: Zebra::Zpl::FontSize::SIZE_2
63
+ )
64
+ label << text
65
+ ```
66
+
67
+ You can add as many elements as you want.
68
+
69
+ ### Printing the labels
70
+
71
+ You need to have your printer visible to CUPS (or shared on the network in Windows). Once your printer is configured and you know its name on CUPS (or the Windows shared printer name), you can send the labels to the printer using a `Zebra::PrintJob` instance.
72
+
73
+ ```ruby
74
+ label = Zebra::Zpl::Label.new(
75
+ width: 200,
76
+ length: 200,
77
+ print_speed: 3
78
+ )
79
+
80
+
81
+ barcode = Zebra::Zpl::Barcode.new(
82
+ data: '12345678',
83
+ position: [50, 50],
84
+ height: 50,
85
+ print_human_readable_code: true,
86
+ narrow_bar_width: 4,
87
+ wide_bar_width: 8,
88
+ type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
89
+ )
90
+
91
+ label << barcode
92
+
93
+ print_job = Zebra::PrintJob.new '<your-printer-name-on-cups/windows-shared-printer-name>'
94
+
95
+ ip = '<IP/Host where the print queue lives>' # can use 'localhost', '127.0.0.1', or '0.0.0.0' for local machine
96
+
97
+ print_job.print label, ip
98
+ ```
99
+
100
+ This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `rlpr -H <hostname/ip> -P <your-printer-name-on-windows> -o <path-to-the-temp-file>` (for Windows systems, see [section](#printing-directly-to-windows-lpd) below) or `lp -h <hostname/ip> -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (for Unix systems). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
101
+
102
+ ##### Print Service
103
+
104
+ You can specify what print service command you want to be used when calling the `print` method by setting the `:print_service` option parameter. If left unspecified, it will attempt to send the print job first via `rlpr` - if the `rlpr` command fails in anyway then it will fall back to the `lp` command.
105
+
106
+ ```ruby
107
+ print_job.print label, ip, print_service: 'lp' # attempt only via the lp command
108
+
109
+ print_job.print label, ip, print_service: 'rlpr' # attempt only via the rlpr command
110
+
111
+ print_job.print label, ip # attempt via rlpr first, fallback to lp
112
+ ```
113
+
114
+ #### Printing directly to Windows LPD
115
+ This gem also supports printing directly to shared printer on Windows using LPD.
116
+ In order to print directly to a LPD on a Windows machine you need two things:
117
+ - [rlpr](http://manpages.ubuntu.com/manpages/xenial/man1/rlpr.1.html) installed on the (UNIX) system running your app that uses this gem.<sup>[1](#fn1)</sup>
118
+ - LPD Print Service and LPR Port Monitor features enabled on the Windows machine.<sup>[2](#fn2)</sup>
119
+
120
+ <p align="center">
121
+ <img align="center" src="http://i.imgur.com/3CWkEWU.png" height="300px"/>
122
+ <p/>
123
+
124
+ <hr/>
125
+
126
+ <sup><a name="fn1">1</a>. On a distro such as Ubuntu simply do: `sudo apt-get install rlpr`
127
+ If using OSX then you will have to manually build it from source and add it to your `$PATH` environment variable.<sup/>
128
+
129
+ <sup><a name="fn2">2</a>. The printer name that you pass in must correspond with the **shared printer name** on the Windows machine.</sup>
130
+
131
+ ## Available elements
132
+
133
+ ### Text
134
+
135
+ <p align="center">
136
+ <img src="docs/images/text.png" width="400">
137
+ </p>
138
+
139
+ You create text elements to print using instances of the `Zebra::Zpl::Text` class. It accepts the following options:
140
+
141
+ * `position`: An array with the coordinates to place the text, in dots.
142
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
143
+ * `data`: The text to be printed.
144
+ * `font_size`: The font size to use. You can use values between 1 and 5.
145
+ * `bold`: The font-weight will be increased via text duplication printing.
146
+ * `reverse_print`: Allows a field to appear as white over black or black over white
147
+
148
+ ### Raw ZPL
149
+
150
+ The `Zebra::Zpl::Raw` class allows you to supply a raw string of ZPL to include on a label. This can be useful for small images, sections of static ZPL that never change, or if you have previously generated ZPL.
151
+
152
+ * `data`: The ZPL string to be printed.
153
+ * `position`: An array with the coordinates to place the text, in dots.
154
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
155
+
156
+ ```ruby
157
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
158
+
159
+ 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"
160
+
161
+ raw_zpl = Zebra::Zpl::Raw.new(
162
+ data: zpl_string,
163
+ position: [50, 50],
164
+ )
165
+
166
+ label << raw_zpl
167
+ ```
168
+
169
+ ### Barcodes
170
+
171
+ <p align="center">
172
+ <img src="docs/images/barcode.png" width="400">
173
+ </p>
174
+
175
+ You create barcode elements to print using instances of the `Zebra::Zpl::Barcode` class. It accepts the following options:
176
+
177
+ * `position`: An array with the coordinates to place the barcode, in dots.
178
+ * `height`: The barcode's height, in dots.
179
+ * `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
180
+ * `data`: The text to be printed.
181
+ * `type`: The type os barcode to use. More on the available types below.
182
+ * `narrow_bar_width`: The barcode's narrow bar width, in dots.
183
+ * `wide_bar_width`: The barcode's wide bar width, in dots.
184
+ * `print_human_readable_code`: Can be `true` or `false`, indicates if the human readable contents should/should not be printed. Default: `false`.
185
+ * `print_text_above`: Can be `true` or `false`, indicates if the human readable contents should be printed above/below the barcode. Default: `false`.
186
+ * `mode`: Can be `N/U/A/D`. Mode value which is optional for `Code 128 Bar Code: CODE_128_AUTO`.
187
+
188
+ The available barcode types are:
189
+
190
+ * `Zebra::Zpl::BarcodeType::CODE_39`
191
+ * `Zebra::Zpl::BarcodeType::CODE_93`
192
+ * `Zebra::Zpl::BarcodeType::CODE_128_AUTO`
193
+ * `Zebra::Zpl::BarcodeType::CODABAR`
194
+ * `Zebra::Zpl::BarcodeType::CODE_AZTEC`
195
+ * `Zebra::Zpl::BarcodeType::CODE_AZTEC_PARAMS`
196
+ * `Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE`
197
+ * `Zebra::Zpl::BarcodeType::CODE_QR`
198
+ * `Zebra::Zpl::BarcodeType::CODE_UPCA`
199
+ * `Zebra::Zpl::BarcodeType::CODE_UPCE`
200
+ * `Zebra::Zpl::BarcodeType::CODE_EAN8`
201
+ * `Zebra::Zpl::BarcodeType::CODE_EAN13`
202
+
203
+ ### QR Codes
204
+
205
+ <p align="center">
206
+ <img src="docs/images/qrcode.png" width="400">
207
+ </p>
208
+
209
+ You can create QR Codes elements to print using instances of the `Zebra::Zpl::Qrcode` class. It accepts the following options:
210
+
211
+ * `position`: An array with the coordinates to place the QR code, in dots.
212
+ * `scale_factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
213
+ * `correction_level`: Algorithm enables reading damaged QR codes. There are four error correction levels: L - 7% of codewords can be restored, M - 15% can be restored, Q - 25% can be restored, H - 30% can be restored.
214
+
215
+ #### Printing QR codes
216
+
217
+ ```ruby
218
+ label = Zebra::Zpl::Label.new(
219
+ width: 350,
220
+ length: 250,
221
+ print_speed: 3
222
+ )
223
+
224
+ qrcode = Zebra::Zpl::Qrcode.new(
225
+ data: 'www.github.com',
226
+ position: [50,10],
227
+ scale_factor: 3,
228
+ correction_level: 'H'
229
+ )
230
+
231
+ label << qrcode
232
+
233
+ print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
234
+
235
+ print_job.print label, '<hostname>'
236
+ ```
237
+
238
+ ### Data Matrix
239
+
240
+ <p align="center">
241
+ <img src="docs/images/datamatrix.png" width="400">
242
+ </p>
243
+
244
+ You can create Data Matrix elements to print using instances of the `Zebra::Zpl::Datamatrix` class. It accepts the following options:
245
+
246
+ * `position`: An array with the coordinates to place the data matrix, in dots.
247
+ * `symbol_height`: Crucial variable of the size size of the data matrix. Accepted values: 1 - label width.
248
+ * `aspect_ratio`: 1 for square, 2 for rectangular.
249
+
250
+ ```ruby
251
+ datamatrix = Zebra::Zpl::Datamatrix.new(
252
+ data: 'www.github.com',
253
+ position: [50,50],
254
+ symbol_height: 5
255
+ )
256
+ ```
257
+
258
+ ### Boxes
259
+
260
+ **&ast;&ast;&ast; The `Zebra::Zpl::Box` class is deprecated and will be removed in future versions. Please switch to the `Zebra::Zpl::Graphic` class (see [Graphics](#graphics) below). &ast;&ast;&ast;**
261
+
262
+ ### Graphics
263
+
264
+ <p align="center">
265
+ <img src="docs/images/graphics.png" width="400">
266
+ </p>
267
+
268
+ You can create graphics elements using the `Zebra::Zpl::Graphic` class:
269
+
270
+ * `position`: An array with the coordinates to place the graphic, in dots.
271
+ * `graphic_type`: Sets the type of graphic:
272
+ * `B`: Box
273
+ * `C`: Circle
274
+ * `D`: Diagonal
275
+ * `E`: Ellipse
276
+ * `S`: Symbol, _see symbol types below._
277
+ * `graphic_width`: Width of the element in dots. (use as the diameter for circles, `C`)
278
+ * `graphic_height`: Height of the element in dots. (does not apply to circles, `C`)
279
+ * `line_thickness`: The thickness of the border in dots.
280
+ * `color`: The color if the lines. B for black, W for white.
281
+ * `orientation`: Only applies to diagonals (graphic type `D`). `R` for right-leaning. `L` for left-leaning.
282
+ * `rounding_degree`: Only applies to boxes (graphic type `B`). Determines what degree to round the corners of the box. Valid values are 0 - 8.
283
+ * `symbol_type`: Only applies to symbols (graphic type `S`). Possible values are:
284
+ * `A`: ® - Registered Trade Mark
285
+ * `B`: © - Copyright
286
+ * `C`: ™ - Trade Mark
287
+ * `D`: (UL) - Underwriters Laboratories approval
288
+ * `E`: (SA) - Canadian Standards Association approval
289
+
290
+ ```ruby
291
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
292
+
293
+ box = Zebra::Zpl::Graphic.new(
294
+ graphic_type: 'B',
295
+ position: [20,25],
296
+ graphic_width: 50,
297
+ graphic_height: 50,
298
+ line_thickness: 2,
299
+ rounding_degree: 2
300
+ )
301
+
302
+ circle = Zebra::Zpl::Graphic.new(
303
+ graphic_type: 'C',
304
+ position: [80,25],
305
+ graphic_width: 50,
306
+ line_thickness: 3
307
+ )
308
+
309
+ diagonal1 = Zebra::Zpl::Graphic.new(
310
+ graphic_type: 'D',
311
+ position: [140,25],
312
+ graphic_width: 50,
313
+ graphic_height: 50,
314
+ line_thickness: 3,
315
+ orientation: 'R'
316
+ )
317
+ diagonal2 = diagonal1.dup
318
+ diagonal2.orientation = 'L'
319
+
320
+ ellipse = Zebra::Zpl::Graphic.new(
321
+ graphic_type: 'E',
322
+ position: [200,25],
323
+ graphic_width: 25,
324
+ graphic_height: 50,
325
+ line_thickness: 3
326
+ )
327
+
328
+ symbol = Zebra::Zpl::Graphic.new(
329
+ graphic_type: 'S',
330
+ symbol_type: 'B',
331
+ position: [235,25],
332
+ graphic_width: 50,
333
+ graphic_height: 50
334
+ )
335
+
336
+ label << box
337
+ label << circle
338
+ label << diagonal1
339
+ label << diagonal2
340
+ label << ellipse
341
+ label << symbol
342
+
343
+ print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
344
+ print_job.print label, '<hostname>'
345
+ ```
346
+
347
+ ### Images
348
+
349
+ <p align="center">
350
+ <img src="docs/images/images.png" width="700">
351
+ </p>
352
+
353
+ You can also create graphics elements from an image using the `Zebra::Zpl::Image` class. Images are converted and encoded into an `^GF` (_Graphics Field_) command using the [img2zpl](https://github.com/mtking2/img2zpl) gem. Accepted parameters are:
354
+
355
+ * `path` (required): The file path or URL of an image.
356
+ * `position`: An array with the coordinates to place the image, in dots.
357
+ * `width`: The width (in pixels) that the image should be printed.
358
+ * `height`: The height (in pixels) that the image should be printed.
359
+ * `rotation`: The number of degrees the image should be rotated
360
+ * unlike the other elements with strict 90° rotations, image elements can be rotated any number of degrees since the image is rotated with imagemagick before conversion to ZPL.
361
+ * `black_threshold`: A value between 0 and 1 that sets the darkness threshold which determines how dark a pixel should be in order to become black in the resulting b/w image. Use larger value for a more saturated image and smaller value for a less saturated one. Default: `0.5`
362
+ * `invert`: set to `true` to invert which pixels are set to black and which are set to white. Default is, depending on the `black_threshold`, dark pixels become black and light pixels become white.
363
+
364
+ #### Usage
365
+ ```ruby
366
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
367
+
368
+ image = Zebra::Zpl::Image.new(
369
+ path: '/path/to/my/image.jpg',
370
+ position: [100, 50],
371
+ width: 200,
372
+ height: 180,
373
+ rotation: -90,
374
+ black_threshold: 0.35
375
+ )
376
+
377
+ label << image
378
+ ```
379
+ **Modifying Images**
380
+
381
+ <p align="center">
382
+ <img src="docs/images/image_manipulation.png" width="500">
383
+ </p>
384
+
385
+ Image elements can also be modified in many ways before being added to the label by calling ImageMagick commands (provided by the [minimagick](https://github.com/minimagick/minimagick) & [img2zpl](https://github.com/mtking2/img2zpl) gems) on the source `Img2Zpl::Image < MiniMagick::Image` object.
386
+
387
+ **Example:** Flattening an image's layers, so it is properly converted, and then trimming out unnecessary white space around the edges:
388
+
389
+ ```ruby
390
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
391
+ image = Zebra::Zpl::Image.new path: 'path/to/image.png', position: [0, 0]
392
+
393
+ img_src = image.source #=> instance of Img2Zpl::Image < MiniMagick::Image
394
+
395
+ img_src.flatten
396
+ img_src.trim
397
+
398
+ label << image
399
+ ```
400
+
401
+ ## Options
402
+
403
+ ### Elements Rotation
404
+
405
+ <p align="center">
406
+ <img src="docs/images/rotation.png" width="400">
407
+ </p>
408
+
409
+ All printable elements can be rotated on the label, using the `:Rotation` option. The accepted rotation values are:
410
+
411
+ * `Zebra::Zpl::Rotation::NO_ROTATION`: will not rotate the element.
412
+ * `Zebra::Zpl::Rotation::DEGREES_90`: will rotate the element 90 degrees.
413
+ * `Zebra::Zpl::Rotation::DEGREES_180`: will rotate the element 180 degrees.
414
+ * `Zebra::Zpl::Rotation::DEGREES_270`: will rotate the element 270 degrees.
415
+
416
+ ### Elements Justification
417
+
418
+ <p align="center">
419
+ <img src="docs/images/justification.png" width="400">
420
+ </p>
421
+
422
+ There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified) is the default.
423
+
424
+ * `Zebra::Zpl::Justification::LEFT` ~ left-justified
425
+ * `Zebra::Zpl::Justification::RIGHT` ~ right-justified
426
+ * `Zebra::Zpl::Justification::CENTER` ~ centered
427
+ * `Zebra::Zpl::Justification::JUSTIFIED` ~ full-width-justifed _(YMMV)_
428
+
429
+ ## Examples
430
+
431
+ See [docs/example.rb](docs/example.rb) for code samples of most elements.
432
+
433
+ ## Contributing
434
+
435
+ See [CONTRIBUTING.md](CONTRIBUTING.md) on how to contribute to this project.
436
+
437
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes by version as well as all the awesome people who have contributed to the project.
438
+
439
+ ## References
440
+
441
+ ###### This is a gem based on a terrific older gem by Cassio Marques. Although the new printers are mostly compatible with old Eltron (Epl) code, our needs require many of the new Zebra (ZPL) functions.
442
+ * [Zebra Technologies Corporation, _"ZPL II Programming Guide."_ 2019 PDF](https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf)