zebra-zpl 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +6 -0
- data/README.md +259 -76
- data/docs/example.rb +249 -0
- data/docs/images/barcode.png +0 -0
- data/docs/images/datamatrix.png +0 -0
- data/docs/images/earth.jpg +0 -0
- data/docs/images/graphics.png +0 -0
- data/docs/images/image.png +0 -0
- data/docs/images/image_inverted.png +0 -0
- data/docs/images/images.png +0 -0
- data/docs/images/justification.png +0 -0
- data/docs/images/qrcode.png +0 -0
- data/docs/images/rotation.png +0 -0
- data/docs/images/text.png +0 -0
- data/lib/zebra/print_job.rb +7 -13
- data/lib/zebra/zpl.rb +20 -13
- data/lib/zebra/zpl/barcode.rb +29 -12
- data/lib/zebra/zpl/barcode_type.rb +4 -1
- data/lib/zebra/zpl/box.rb +16 -4
- data/lib/zebra/zpl/comment.rb +15 -0
- data/lib/zebra/zpl/datamatrix.rb +76 -0
- data/lib/zebra/zpl/graphic.rb +91 -0
- data/lib/zebra/zpl/image.rb +91 -0
- data/lib/zebra/zpl/label.rb +2 -13
- data/lib/zebra/zpl/pdf417.rb +50 -0
- data/lib/zebra/zpl/qrcode.rb +2 -2
- data/lib/zebra/zpl/text.rb +44 -20
- data/lib/zebra/zpl/version.rb +1 -1
- data/spec/fixtures/default.jpg +0 -0
- data/spec/spec_helper.rb +6 -2
- data/spec/zebra/print_job_spec.rb +13 -18
- data/spec/zebra/zpl/barcode_spec.rb +70 -63
- data/spec/zebra/zpl/box_spec.rb +27 -31
- data/spec/zebra/zpl/character_set_spec.rb +7 -7
- data/spec/zebra/zpl/comment_spec.rb +18 -0
- data/spec/zebra/zpl/datamatrix_spec.rb +124 -0
- data/spec/zebra/zpl/graphics_spec.rb +227 -0
- data/spec/zebra/zpl/image_spec.rb +113 -0
- data/spec/zebra/zpl/label_spec.rb +40 -52
- data/spec/zebra/zpl/pdf417_spec.rb +108 -0
- data/spec/zebra/zpl/qrcode_spec.rb +92 -92
- data/spec/zebra/zpl/text_spec.rb +57 -55
- data/zebra-zpl.gemspec +14 -15
- metadata +71 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faa19461aac4741df172e4172665a34e25d7be83b925e9da52d23a9afe398c13
|
4
|
+
data.tar.gz: dc6f760289525d0a06654e6b706ca11be6f55d1c5e2baa70b6851104b0a34571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae75990790ea00a4f036f0c8aa015db79cc6c481988e3f8ba9014f2ff6cf941895c2e875c9149dcf62fe59a457a378447827f8b0e9a5fc51a1a76275bed93704
|
7
|
+
data.tar.gz: e7895c004ef9ff44b9cd32edbe6d870b58d92fb2970f373f8fe468d8703ede85ccf43cb93cdc932eb1ebb04e363be127a09bbcd30d1c281cb5140b22c62cc233
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
### 1.1.1 (next)
|
2
|
+
|
3
|
+
* Your contribution here.
|
4
|
+
|
5
|
+
### 1.1.0 (11/04/2019)
|
6
|
+
|
7
|
+
* [#54](https://github.com/bbulpett/zebra-zpl/pull/54): Fix height bug with ^B commands - [@mtking2](https://github.com/mtking2)
|
8
|
+
* [#53](https://github.com/bbulpett/zebra-zpl/pull/53): Added support for symbol types, fixed other bugs with the `Graphic` class, updated specs - [@mtking2](https://github.com/mtking2)
|
9
|
+
* [#50](https://github.com/bbulpett/zebra-zpl/pull/50): Add support for image elements by incorporating the [img2zpl](https://github.com/mtking2/img2zpl) gem - [@mtking2](https://github.com/mtking2)
|
10
|
+
* [#49](https://github.com/bbulpett/zebra-zpl/pull/49): Fixed bug with `Barcode`'s `^BY` command. Added UPCA, UPCE, & EAN13 types - [@mtking2](https://github.com/mtking2)
|
11
|
+
* [#48](https://github.com/bbulpett/zebra-zpl/pull/48): Fixed bug breaking `Text` elements. Added rspecs for `Datamatrix` - [@mtking2](https://github.com/mtking2)
|
12
|
+
* [#45](https://github.com/bbulpett/zebra-zpl/pull/45): Add CHANGELOG & update README - [@mtking2](https://github.com/mtking2)
|
13
|
+
* [#44](https://github.com/bbulpett/zebra-zpl/pull/44): Update README & add more docs - [@mtking2](https://github.com/mtking2)
|
14
|
+
* [#43](https://github.com/bbulpett/zebra-zpl/pull/43): Add ZPL comment element - [@LagTag](https://github.com/LagTag)
|
15
|
+
* [#42](https://github.com/bbulpett/zebra-zpl/pull/42): Consolidate Graphic Elements to One Class. Deprecate `Box` class - [@LagTag](https://github.com/LagTag)
|
16
|
+
* [#41](https://github.com/bbulpett/zebra-zpl/pull/41): Ability to pass ZPL string to PrintJob - [@LagTag](https://github.com/LagTag)
|
17
|
+
* [#40](https://github.com/bbulpett/zebra-zpl/pull/40): Bold Text - [@LagTag](https://github.com/LagTag)
|
18
|
+
* [#39](https://github.com/bbulpett/zebra-zpl/pull/39): Fix specs + minor maintenance - [@mtking2](https://github.com/mtking2)
|
19
|
+
* [#36](https://github.com/bbulpett/zebra-zpl/pull/36): Add Datamatrix - [@rafaelmf3](https://github.com/rafaelmf3)
|
20
|
+
* [#33](https://github.com/bbulpett/zebra-zpl/pull/33): Remove the hardcoded attributes for the box element - [@LagTag](https://github.com/LagTag)
|
21
|
+
* [#32](https://github.com/bbulpett/zebra-zpl/pull/32): Added diagonal line graphic (^GD) - [@LagTag](https://github.com/LagTag)
|
22
|
+
* [#31](https://github.com/bbulpett/zebra-zpl/pull/31): Added Circle Graphic (^GC) - [@LagTag](https://github.com/LagTag)
|
23
|
+
* [#29](https://github.com/bbulpett/zebra-zpl/pull/29): Removed hard coded attributes in Text Element - [@LagTag](https://github.com/LagTag)
|
24
|
+
* [#27](https://github.com/bbulpett/zebra-zpl/pull/27): Added pdf417 support - [@LagTag](https://github.com/LagTag)
|
25
|
+
* [#25](https://github.com/bbulpett/zebra-zpl/pull/25): Don't Overwrite Element Widths - [@LagTag](https://github.com/LagTag)
|
26
|
+
|
27
|
+
### 1.0.5 (2018/10/25)
|
28
|
+
|
29
|
+
* [#22](https://github.com/bbulpett/zebra-zpl/pull/22): update label print density range from 0-6 to 0-15 - [@steve-abrams](https://github.com/steve-abrams)
|
30
|
+
* [#21](https://github.com/bbulpett/zebra-zpl/pull/21): Support QR codes (fixed) - [@mtking2](https://github.com/mtking2)
|
31
|
+
* [#20](https://github.com/bbulpett/zebra-zpl/pull/20): Fix incorrect raw flag - [@mtking2](https://github.com/mtking2)
|
32
|
+
|
33
|
+
### 1.0.4 (2017/10/27)
|
34
|
+
|
35
|
+
* [#15](https://github.com/bbulpett/zebra-zpl/pull/15): Raw ZPL support - [@bbulpett](https://github.com/bbulpett)
|
36
|
+
|
37
|
+
### 1.0.3 (2017/06/12)
|
38
|
+
|
39
|
+
* [#14](https://github.com/bbulpett/zebra-zpl/pull/14): Version bump to 1.0.3 - [@bbulpett](https://github.com/bbulpett)
|
40
|
+
* [#13](https://github.com/bbulpett/zebra-zpl/pull/13): Windows Printing Support - [@mtking2](https://github.com/mtking2)
|
41
|
+
|
42
|
+
### 1.0.2 (2017/04/27)
|
43
|
+
|
44
|
+
* [ead84a4](https://github.com/bbulpett/zebra-zpl/commit/ead84a4170f291e9a121263ac0ce577b9b5b21ba): Revert to Unix-only `lp` - [@bbulpett](https://github.com/bbulpett)
|
45
|
+
|
46
|
+
### 1.0.1 (2017/04/26)
|
47
|
+
|
48
|
+
* [b5e3f3e](https://github.com/bbulpett/zebra-zpl/commit/b5e3f3ea41960ce953073dcf1b09c28047a17b0d): Attempt `lpr` for Windows if Unix `lp` fails - [@bbulpett](https://github.com/bbulpett)
|
49
|
+
* [3858b33](https://github.com/bbulpett/zebra-zpl/commit/3858b332491d7afe34277d43530e0da7462da2b1): Use SSL for homepage in gemspec - [@bbulpett](https://github.com/bbulpett)
|
50
|
+
|
51
|
+
### 1.0.0 (2017/04/26)
|
52
|
+
|
53
|
+
* [#10](https://github.com/bbulpett/zebra-zpl/pull/10): Add side margins - [@bbulpett](https://github.com/bbulpett)
|
54
|
+
* [#9](https://github.com/bbulpett/zebra-zpl/pull/9): Add padding to sides for text blocks - [@bbulpett](https://github.com/bbulpett)
|
55
|
+
* [#8](https://github.com/bbulpett/zebra-zpl/pull/8): Add rotation to zpl builders - [@bbulpett](https://github.com/bbulpett)
|
56
|
+
* [#7](https://github.com/bbulpett/zebra-zpl/pull/7): Add international text support and apply label width to zpl builder methods - [@bbulpett](https://github.com/bbulpett)
|
57
|
+
* [#6](https://github.com/bbulpett/zebra-zpl/pull/6): Font modifications - [@bbulpett](https://github.com/bbulpett)
|
58
|
+
* [#5](https://github.com/bbulpett/zebra-zpl/pull/5): Restore barcode functionality - [@bbulpett](https://github.com/bbulpett)
|
59
|
+
* [#4](https://github.com/bbulpett/zebra-zpl/pull/4): Orientation module - [@bbulpett](https://github.com/bbulpett)
|
60
|
+
* [#3](https://github.com/bbulpett/zebra-zpl/pull/3): Restore zpl barcode logic - [@bbulpett](https://github.com/bbulpett)
|
61
|
+
* [#2](https://github.com/bbulpett/zebra-zpl/pull/2): ZPL barcodes tested and working - [@bbulpett](https://github.com/bbulpett)
|
62
|
+
* [#1](https://github.com/bbulpett/zebra-zpl/pull/1): Convert zpl method, class, and file namings - [@bbulpett](https://github.com/bbulpett)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Check [open issues](https://github.com/bbulpett/zebra-zpl/issues) for things that need work.
|
4
|
+
Also check any [open pull requests](https://github.com/bbulpett/zebra-zpl/pulls) to make sure any changes you want to make haven't already been made by someone else.
|
5
|
+
|
6
|
+
### Fork & clone the repository
|
7
|
+
|
8
|
+
```
|
9
|
+
git clone git@github.com:<your-username>/zebra-zpl.git
|
10
|
+
cd zebra-zpl
|
11
|
+
git remote add upstream git@github.com:bbulpett/zebra-zpl.git
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
Then check out a working branch:
|
16
|
+
|
17
|
+
```
|
18
|
+
git checkout -b <my-working-branch>
|
19
|
+
```
|
20
|
+
|
21
|
+
### Write tests
|
22
|
+
|
23
|
+
This project uses `rspec`. After writing your tests, you can run tests with the following command:
|
24
|
+
|
25
|
+
`bundle exec rspec`
|
26
|
+
|
27
|
+
|
28
|
+
### Write code
|
29
|
+
|
30
|
+
Write your code to make your tests pass.
|
31
|
+
|
32
|
+
### Update the CHANGELOG with a description and your name
|
33
|
+
|
34
|
+
Update `CHANGELOG.md` with the description of your code changes and your name on the line after `"* Your contribution here"`.
|
35
|
+
|
36
|
+
### Commit & Push your changes
|
37
|
+
|
38
|
+
Commit and push your changes to your working branch.
|
39
|
+
|
40
|
+
```
|
41
|
+
git commit -am 'Add some feature'
|
42
|
+
git push origin <my-working-branch>
|
43
|
+
```
|
44
|
+
|
45
|
+
### Open a pull request
|
46
|
+
|
47
|
+
Open a pull request against upstream master and your working branch. Give a brief description of what your PR does and explain what the code changes do.
|
48
|
+
|
49
|
+
Thank you!
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,30 @@
|
|
1
|
-
#### 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, my needs require many of the new Zebra (ZPL) functions.
|
2
|
-
|
3
1
|
# Zebra::Zpl
|
4
2
|
|
5
|
-
|
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)
|
6
5
|
|
7
6
|
Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
|
8
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
|
+
|
9
28
|
## Installation
|
10
29
|
|
11
30
|
Add this line to your application's Gemfile:
|
@@ -14,11 +33,11 @@ Add this line to your application's Gemfile:
|
|
14
33
|
|
15
34
|
And then execute:
|
16
35
|
|
17
|
-
|
36
|
+
bundle install
|
18
37
|
|
19
38
|
Or install it yourself as:
|
20
39
|
|
21
|
-
|
40
|
+
gem install zebra-zpl
|
22
41
|
|
23
42
|
## Usage
|
24
43
|
|
@@ -29,15 +48,19 @@ You create new labels with an instance of the `Zebra::Zpl::Label` class. It acce
|
|
29
48
|
* `copies`: The number of copies to print. This option defaults to 1.
|
30
49
|
* `width`: The label's width, in dots.
|
31
50
|
* `length`: The label's length, is dots.
|
32
|
-
* `gap`: The gap between labels, in dots.
|
33
51
|
* `print_speed`: The print speed to be used. You can use values between 0 and 6. This option is required.
|
34
|
-
* `print_density`: The print density to be used. You can use values between 0 and 15. This option is required.
|
35
52
|
|
36
53
|
With a label, you can start adding elements to it:
|
37
54
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
+
```
|
41
64
|
|
42
65
|
You can add as many elements as you want.
|
43
66
|
|
@@ -45,82 +68,65 @@ You can add as many elements as you want.
|
|
45
68
|
|
46
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.
|
47
70
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
71
|
+
```ruby
|
72
|
+
label = Zebra::Zpl::Label.new(
|
73
|
+
width: 200,
|
74
|
+
length: 200,
|
75
|
+
print_speed: 3
|
76
|
+
)
|
54
77
|
|
55
78
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
+
)
|
65
88
|
|
66
|
-
|
89
|
+
label << barcode
|
67
90
|
|
68
|
-
|
91
|
+
print_job = Zebra::PrintJob.new '<your-printer-name-on-cups/windows-shared-printer-name>'
|
69
92
|
|
70
|
-
|
93
|
+
ip = '<IP/Host where the print queue lives>' # can use 'localhost', '127.0.0.1', or '0.0.0.0' for local machine
|
71
94
|
|
72
|
-
|
95
|
+
print_job.print label, ip
|
96
|
+
```
|
73
97
|
|
74
|
-
|
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
|
+
#### Printing directly to Windows LPD
|
75
101
|
This gem also supports printing directly to shared printer on Windows using LPD.
|
76
102
|
In order to print directly to a LPD on a Windows machine you need two things:
|
77
103
|
- [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>
|
78
104
|
- LPD Print Service and LPR Port Monitor features enabled on the Windows machine.<sup>[2](#fn2)</sup>
|
79
105
|
|
80
106
|
<p align="center">
|
81
|
-
<img align="center" src="http://i.imgur.com/3CWkEWU.png"
|
107
|
+
<img align="center" src="http://i.imgur.com/3CWkEWU.png" height="300px"/>
|
82
108
|
<p/>
|
83
109
|
|
84
110
|
<hr/>
|
85
111
|
|
86
|
-
<a name="fn1">1</a>. On a distro such as Ubuntu simply do: `sudo apt-get install rlpr`
|
87
|
-
If using OSX then you will have to manually build it from source and add it to your `$PATH` environment variable
|
88
|
-
|
89
|
-
<a name="fn2">2</a>. The printer name that you pass in must correspond with the **shared printer name** on the Windows machine.
|
112
|
+
<sup><a name="fn1">1</a>. On a distro such as Ubuntu simply do: `sudo apt-get install rlpr`
|
113
|
+
If using OSX then you will have to manually build it from source and add it to your `$PATH` environment variable.<sup/>
|
90
114
|
|
91
|
-
|
115
|
+
<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>
|
92
116
|
|
93
|
-
|
94
|
-
:width=>350,
|
95
|
-
:length=>250,
|
96
|
-
:print_speed=>3,
|
97
|
-
:print_density=>6
|
98
|
-
)
|
117
|
+
## Available elements
|
99
118
|
|
100
|
-
|
101
|
-
:data=>"www.github.com",
|
102
|
-
:position=>[50,10],
|
103
|
-
:scale_factor=>3,
|
104
|
-
:correction_level=>"H"
|
105
|
-
)
|
119
|
+
### Text
|
106
120
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
print_job.print label
|
112
|
-
|
113
|
-
### Available elements
|
114
|
-
|
115
|
-
#### Text
|
121
|
+
<p align="center">
|
122
|
+
<img src="docs/images/text.png" width="400">
|
123
|
+
</p>
|
116
124
|
|
117
125
|
You create text elements to print using instances of the `Zebra::Zpl::Text` class. It accepts the following options:
|
118
126
|
|
119
127
|
* `position`: An array with the coordinates to place the text, in dots.
|
120
|
-
* `rotation`: The rotation for the text. More about the possible values below.
|
128
|
+
* `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
|
121
129
|
* `data`: The text to be printed.
|
122
|
-
* `v_multiplier`: The vertical multiplier to use.
|
123
|
-
* `h_multiplier`: The horizontal multipler to use.
|
124
130
|
* `print_mode`: The print mode. Can be normal ("N") or reverse ("R").
|
125
131
|
* `font_size`: The font size to use. You can use values between 1 and 5.
|
126
132
|
|
@@ -130,13 +136,17 @@ For the print modes, you can also use the constants:
|
|
130
136
|
* `Zebra::Zpl::PrintMode::REVERSE`
|
131
137
|
|
132
138
|
|
133
|
-
|
139
|
+
### Barcodes
|
140
|
+
|
141
|
+
<p align="center">
|
142
|
+
<img src="docs/images/barcode.png" width="400">
|
143
|
+
</p>
|
134
144
|
|
135
145
|
You create barcode elements to print using instances of the `Zebra::Zpl::Barcode` class. It accepts the following options:
|
136
146
|
|
137
|
-
* `position`: An array with the coordinates to place the
|
147
|
+
* `position`: An array with the coordinates to place the barcode, in dots.
|
138
148
|
* `height`: The barcode's height, in dots.
|
139
|
-
* `rotation`: The rotation for the text. More about the possible values below.
|
149
|
+
* `rotation`: The rotation for the text. More about the possible values below (see [Rotation](#elements-rotation) section).
|
140
150
|
* `data`: The text to be printed.
|
141
151
|
* `type`: The type os barcode to use. More on the available types below.
|
142
152
|
* `narrow_bar_width`: The barcode's narrow bar width, in dots.
|
@@ -154,21 +164,185 @@ The available barcode types are:
|
|
154
164
|
* `Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE`
|
155
165
|
* `Zebra::Zpl::BarcodeType::CODE_QR`
|
156
166
|
|
157
|
-
|
167
|
+
### QR Codes
|
168
|
+
|
169
|
+
<p align="center">
|
170
|
+
<img src="docs/images/qrcode.png" width="400">
|
171
|
+
</p>
|
158
172
|
|
159
173
|
You can create QR Codes elements to print using instances of the `Zebra::Zpl::Qrcode` class. It accepts the following options:
|
160
174
|
|
161
175
|
* `position`: An array with the coordinates to place the QR code, in dots.
|
162
|
-
* `
|
163
|
-
* `
|
176
|
+
* `scale_factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
|
177
|
+
* `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.
|
164
178
|
|
165
|
-
####
|
179
|
+
#### Printing QR codes
|
166
180
|
|
167
|
-
|
181
|
+
```ruby
|
182
|
+
label = Zebra::Zpl::Label.new(
|
183
|
+
width: 350,
|
184
|
+
length: 250,
|
185
|
+
print_speed: 3
|
186
|
+
)
|
168
187
|
|
169
|
-
|
188
|
+
qrcode = Zebra::Zpl::Qrcode.new(
|
189
|
+
data: 'www.github.com',
|
190
|
+
position: [50,10],
|
191
|
+
scale_factor: 3,
|
192
|
+
correction_level: 'H'
|
193
|
+
)
|
170
194
|
|
171
|
-
|
195
|
+
label << qrcode
|
196
|
+
|
197
|
+
print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
|
198
|
+
|
199
|
+
print_job.print label, '<hostname>'
|
200
|
+
```
|
201
|
+
|
202
|
+
### Data Matrix
|
203
|
+
|
204
|
+
<p align="center">
|
205
|
+
<img src="docs/images/datamatrix.png" width="400">
|
206
|
+
</p>
|
207
|
+
|
208
|
+
You can create Data Matrix elements to print using instances of the `Zebra::Zpl::Datamatrix` class. It accepts the following options:
|
209
|
+
|
210
|
+
* `position`: An array with the coordinates to place the data matrix, in dots.
|
211
|
+
* `symbol_height`: Crucial variable of the size size of the data matrix. Accepted values: 1 - label width.
|
212
|
+
* `aspect_ratio`: 1 for square, 2 for rectangular.
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
datamatrix = Zebra::Zpl::Datamatrix.new(
|
216
|
+
data: 'www.github.com',
|
217
|
+
position: [50,50],
|
218
|
+
symbol_height: 5
|
219
|
+
)
|
220
|
+
```
|
221
|
+
|
222
|
+
### Boxes
|
223
|
+
|
224
|
+
***** 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). *****
|
225
|
+
|
226
|
+
### Graphics
|
227
|
+
|
228
|
+
<p align="center">
|
229
|
+
<img src="docs/images/graphics.png" width="400">
|
230
|
+
</p>
|
231
|
+
|
232
|
+
You can create graphics elements using the `Zebra::Zpl::Graphic` class:
|
233
|
+
|
234
|
+
* `position`: An array with the coordinates to place the graphic, in dots.
|
235
|
+
* `graphic_type`: Sets the type of graphic:
|
236
|
+
* `B`: Box
|
237
|
+
* `C`: Circle
|
238
|
+
* `D`: Diagonal
|
239
|
+
* `E`: Ellipse
|
240
|
+
* `S`: Symbol, _see symbol types below._
|
241
|
+
* `graphic_width`: Width of the element in dots. (use as the diameter for circles, `C`)
|
242
|
+
* `graphic_height`: Height of the element in dots. (does not apply to circles, `C`)
|
243
|
+
* `line_thickness`: The thickness of the border in dots.
|
244
|
+
* `color`: The color if the lines. B for black, W for white.
|
245
|
+
* `orientation`: Only applies to diagonals (graphic type `D`). `R` for right-leaning. `L` for left-leaning.
|
246
|
+
* `rounding_degree`: Only applies to boxes (graphic type `B`). Determines what degree to round the corners of the box. Valid values are 0 - 8.
|
247
|
+
* `symbol_type`: Only applies to symbols (graphic type `S`). Possible values are:
|
248
|
+
* `A`: ® - Registered Trade Mark
|
249
|
+
* `B`: © - Copyright
|
250
|
+
* `C`: ™ - Trade Mark
|
251
|
+
* `D`: (UL) - Underwriters Laboratories approval
|
252
|
+
* `E`: (SA) - Canadian Standards Association approval
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
|
256
|
+
|
257
|
+
box = Zebra::Zpl::Graphic.new(
|
258
|
+
graphic_type: 'B',
|
259
|
+
position: [20,25],
|
260
|
+
graphic_width: 50,
|
261
|
+
graphic_height: 50,
|
262
|
+
line_thickness: 2,
|
263
|
+
rounding_degree: 2
|
264
|
+
)
|
265
|
+
|
266
|
+
circle = Zebra::Zpl::Graphic.new(
|
267
|
+
graphic_type: 'C',
|
268
|
+
position: [80,25],
|
269
|
+
graphic_width: 50,
|
270
|
+
line_thickness: 3
|
271
|
+
)
|
272
|
+
|
273
|
+
diagonal1 = Zebra::Zpl::Graphic.new(
|
274
|
+
graphic_type: 'D',
|
275
|
+
position: [140,25],
|
276
|
+
graphic_width: 50,
|
277
|
+
graphic_height: 50,
|
278
|
+
line_thickness: 3,
|
279
|
+
orientation: 'R'
|
280
|
+
)
|
281
|
+
diagonal2 = diagonal1.dup
|
282
|
+
diagonal2.orientation = 'L'
|
283
|
+
|
284
|
+
ellipse = Zebra::Zpl::Graphic.new(
|
285
|
+
graphic_type: 'E',
|
286
|
+
position: [200,25],
|
287
|
+
graphic_width: 25,
|
288
|
+
graphic_height: 50,
|
289
|
+
line_thickness: 3
|
290
|
+
)
|
291
|
+
|
292
|
+
symbol = Zebra::Zpl::Graphic.new(
|
293
|
+
graphic_type: 'S',
|
294
|
+
symbol_type: 'B',
|
295
|
+
position: [235,25],
|
296
|
+
graphic_width: 50,
|
297
|
+
graphic_height: 50
|
298
|
+
)
|
299
|
+
|
300
|
+
label << box
|
301
|
+
label << circle
|
302
|
+
label << diagonal1
|
303
|
+
label << diagonal2
|
304
|
+
label << ellipse
|
305
|
+
label << symbol
|
306
|
+
|
307
|
+
print_job = Zebra::PrintJob.new '<your-qr-printer-name-on-cups>'
|
308
|
+
print_job.print label, '<hostname>'
|
309
|
+
```
|
310
|
+
|
311
|
+
### Images
|
312
|
+
|
313
|
+
<p align="center">
|
314
|
+
<img src="docs/images/images.png" width="700">
|
315
|
+
</p>
|
316
|
+
|
317
|
+
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:
|
318
|
+
|
319
|
+
* `path` (required): The file path or URL of an image.
|
320
|
+
* `position`: An array with the coordinates to place the image, in dots.
|
321
|
+
* `width`: The width (in pixels) that the image should be printed.
|
322
|
+
* `height`: The height (in pixels) that the image should be printed.
|
323
|
+
* `rotation`: The number of degrees the image should be rotated
|
324
|
+
* 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.
|
325
|
+
* `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`
|
326
|
+
* `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.
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
image = Zebra::Zpl::Image.new(
|
330
|
+
path: '/path/to/my/image.jpg',
|
331
|
+
position: [100, 50],
|
332
|
+
width: 200,
|
333
|
+
height: 180,
|
334
|
+
rotation: -90,
|
335
|
+
black_threshold: 0.35
|
336
|
+
)
|
337
|
+
```
|
338
|
+
|
339
|
+
## Options
|
340
|
+
|
341
|
+
### Elements Rotation
|
342
|
+
|
343
|
+
<p align="center">
|
344
|
+
<img src="docs/images/rotation.png" width="400">
|
345
|
+
</p>
|
172
346
|
|
173
347
|
All printable elements can be rotated on the label, using the `:Rotation` option. The accepted rotation values are:
|
174
348
|
|
@@ -177,7 +351,11 @@ All printable elements can be rotated on the label, using the `:Rotation` option
|
|
177
351
|
* `Zebra::Zpl::Rotation::DEGREES_180`: will rotate the element 180 degrees.
|
178
352
|
* `Zebra::Zpl::Rotation::DEGREES_270`: will rotate the element 270 degrees.
|
179
353
|
|
180
|
-
|
354
|
+
### Elements Justification
|
355
|
+
|
356
|
+
<p align="center">
|
357
|
+
<img src="docs/images/justification.png" width="400">
|
358
|
+
</p>
|
181
359
|
|
182
360
|
There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified) is the default.
|
183
361
|
|
@@ -186,12 +364,17 @@ There are four ZPL-supported `:Justification` parameters. "LEFT" (left-justified
|
|
186
364
|
* `Zebra::Zpl::Justification::CENTER` ~ centered
|
187
365
|
* `Zebra::Zpl::Justification::JUSTIFIED` ~ full-width-justifed _(YMMV)_
|
188
366
|
|
367
|
+
## Examples
|
189
368
|
|
369
|
+
See [docs/example.rb](docs/example.rb) for code samples of most elements.
|
190
370
|
|
191
371
|
## Contributing
|
192
372
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
373
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) on how to contribute to this project.
|
374
|
+
|
375
|
+
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.
|
376
|
+
|
377
|
+
## References
|
378
|
+
|
379
|
+
###### 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.
|
380
|
+
* [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)
|