zebra-zpl 1.0.2 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4601d04149c76a88c86a00b57b76b004ff603183
4
- data.tar.gz: 75b6773cd9f63a0d9ca27e5b799949d076dfb150
2
+ SHA256:
3
+ metadata.gz: 92378659f6249cc45837419bc1204838c1f67e7e11c31882fdfa0dc425d1095d
4
+ data.tar.gz: 7e0ad872079f42fe1d488eb63661eb8f88774fd923fb55d0e4cdbaa5f6d1798d
5
5
  SHA512:
6
- metadata.gz: 3883a043edbe74c0d9e8847f3ca3c48ef9c16605d703cc5efcd400623ab833cdb11706249412c5828d32bc2b3139dce1efd34c3e70ac503769ad0265fde5b25d
7
- data.tar.gz: eb2baa12fff0b2b6eddc69692fea622ec2d7474947965ec9a6792196a3aa23f210671436e86783e44a09b08df32c261812f78668430bb0d5e05d988ce3eccb76
6
+ metadata.gz: d27c1848ce9ab4a8085a90fa66b3445c000da70991dd56cf8d67eb443cd3bcefbf90799f44d4aabdf374c386beb541e0805052d21873afe6751ae15b22ce2b71
7
+ data.tar.gz: b78426a6731bdddd527105dfef0b0046b946c1b550a1ccb791e711f75ab36ea159da53380f38b2f23dd81accc6c43444fbee484f146317a31005e51585d7e5d3
data/README.md CHANGED
@@ -1,10 +1,10 @@
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.
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
2
 
3
3
  # Zebra::Zpl
4
4
 
5
5
  ### ToDo: Update documentation with instructions for new features such as font sizing, margins, and text alignment
6
6
 
7
- Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
7
+ Zebra::Zpl offers a Ruby DSL to design and print labels using the ZPL programming language.
8
8
 
9
9
  ## Installation
10
10
 
@@ -38,12 +38,12 @@ With a label, you can start adding elements to it:
38
38
  label = Zebra::Zpl::Label.new :print_density => 8, :print_speed => 3
39
39
  text = Zebra::Zpl::Text.new :data => "Hello, printer!", :position => [100, 100], :font_size => Zebra::Zpl::FontSize::SIZE_2
40
40
  label << text
41
-
41
+
42
42
  You can add as many elements as you want.
43
43
 
44
44
  ### Printing the labels
45
45
 
46
- You need to have your printer visible to CUPS. Once your printer is configured and you know its name on CUPS, you can send the labels to the printer using a `Zebra::PrintJob` instance.
46
+ 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
47
 
48
48
  label = Zebra::Zpl::Label.new(
49
49
  :width => 200,
@@ -51,8 +51,8 @@ You need to have your printer visible to CUPS. Once your printer is configured a
51
51
  :print_speed => 3,
52
52
  :print_density => 6
53
53
  )
54
-
55
-
54
+
55
+
56
56
  barcode = Zebra::Zpl::Barcode.new(
57
57
  :data => "12345678",
58
58
  :position => [50, 50],
@@ -62,14 +62,31 @@ You need to have your printer visible to CUPS. Once your printer is configured a
62
62
  :wide_bar_width => 8,
63
63
  :type => Zebra::Zpl::BarcodeType::CODE_128_AUTO
64
64
  )
65
-
65
+
66
66
  label << barcode
67
-
68
- print_job = Zebra::PrintJob.new "your-printer-name-on-cups"
69
-
67
+
68
+ print_job = Zebra::PrintJob.new "<your-printer-name-on-cups/windows-shared-printer-name>"
69
+
70
70
  print_job.print label
71
71
 
72
- This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `lpr -P <your-printer-name-on-cups> -o raw <path-to-the-temp-file>` (if you're on Mac OSX) or `lp -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (if you're on Linux). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
72
+ This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `lpr -P <your-printer-name-on-cups> -o raw <path-to-the-temp-file>` (if you're on Mac OSX) or `lp -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (if you're on Linux). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
73
+
74
+ ### Printing to directly to Windows LPD
75
+ This gem also supports printing directly to shared printer on Windows using LPD.
76
+ In order to print directly to a LPD on a Windows machine you need two things:
77
+ - [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
+ - LPD Print Service and LPR Port Monitor features enabled on the Windows machine.<sup>[2](#fn2)</sup>
79
+
80
+ <p align="center">
81
+ <img align="center" src="http://i.imgur.com/3CWkEWU.png" style="height: 250px"/>
82
+ <p/>
83
+
84
+ <hr/>
85
+
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.
73
90
 
74
91
  ### Printing QR codes
75
92
 
@@ -92,17 +109,17 @@ This will persist the label contents to a tempfile (using Ruby's tempfile core l
92
109
  print_job = Zebra::PrintJob.new "your-qr-printer-name-on-cups"
93
110
 
94
111
  print_job.print label
95
-
112
+
96
113
  ### Available elements
97
114
 
98
115
  #### Text
99
116
 
100
117
  You create text elements to print using instances of the `Zebra::Zpl::Text` class. It accepts the following options:
101
118
 
102
- * `position`: An array with the coordinates to place the text, in dots.
119
+ * `position`: An array with the coordinates to place the text, in dots.
103
120
  * `rotation`: The rotation for the text. More about the possible values below.
104
121
  * `data`: The text to be printed.
105
- * `v_multiplier`: The vertical multiplier to use.
122
+ * `v_multiplier`: The vertical multiplier to use.
106
123
  * `h_multiplier`: The horizontal multipler to use.
107
124
  * `print_mode`: The print mode. Can be normal ("N") or reverse ("R").
108
125
  * `font_size`: The font size to use. You can use values between 1 and 5.
@@ -117,7 +134,7 @@ For the print modes, you can also use the constants:
117
134
 
118
135
  You create barcode elements to print using instances of the `Zebra::Zpl::Barcode` class. It accepts the following options:
119
136
 
120
- * `position`: An array with the coordinates to place the text, in dots.
137
+ * `position`: An array with the coordinates to place the text, in dots.
121
138
  * `height`: The barcode's height, in dots.
122
139
  * `rotation`: The rotation for the text. More about the possible values below.
123
140
  * `data`: The text to be printed.
@@ -150,7 +167,7 @@ You can create QR Codes elements to print using instances of the `Zebra::Zpl::Qr
150
167
  You can draw boxes in your labels:
151
168
 
152
169
  box = Zebra::Zpl::Box.new :position => [20, 20], :end_position => [100, 100], :line_thickness => 39
153
-
170
+
154
171
  #### Elements Rotation
155
172
 
156
173
  All printable elements can be rotated on the label, using the `:Rotation` option. The accepted rotation values are:
@@ -29,7 +29,8 @@ module Zebra
29
29
 
30
30
  def send_to_printer(path)
31
31
  puts "* * * * * * * * * * * * Sending file to printer #{@printer} at #{@remote_ip} * * * * * * * * * * "
32
- `lp -h #{@remote_ip} -d #{@printer} -o raw #{path}`
32
+ result = system("rlpr -H #{@remote_ip} -P #{@printer} -o #{path} 2>&1") # try printing to LPD on windows machine first
33
+ system("lp -h #{@remote_ip} -d #{@printer} -o raw #{path}") if !result # print to unix (CUPS) if rlpr failed
33
34
  end
34
35
  end
35
36
  end
@@ -1,18 +1,19 @@
1
- require "cups"
2
- require "tempfile"
3
- require "zebra/zpl/version"
4
- require "zebra/zpl/language"
5
- require "zebra/zpl/country_code"
6
- require "zebra/zpl/character_set"
7
- require "zebra/zpl/rotation"
8
- require "zebra/zpl/multipliers"
9
- require "zebra/zpl/print_mode"
10
- require "zebra/zpl/font"
11
- require "zebra/zpl/box"
12
- require "zebra/zpl/label"
13
- require "zebra/zpl/text"
14
- require "zebra/zpl/barcode"
15
- require "zebra/zpl/barcode_type"
16
- require "zebra/print_job"
17
- require "zebra/zpl/qrcode"
18
- require "zebra/zpl/justification"
1
+ # require 'cups'
2
+ require 'tempfile'
3
+ require 'zebra/zpl/version'
4
+ require 'zebra/zpl/language'
5
+ require 'zebra/zpl/country_code'
6
+ require 'zebra/zpl/character_set'
7
+ require 'zebra/zpl/rotation'
8
+ require 'zebra/zpl/multipliers'
9
+ require 'zebra/zpl/print_mode'
10
+ require 'zebra/zpl/font'
11
+ require 'zebra/zpl/box'
12
+ require 'zebra/zpl/label'
13
+ require 'zebra/zpl/text'
14
+ require 'zebra/zpl/barcode'
15
+ require 'zebra/zpl/barcode_type'
16
+ require 'zebra/print_job'
17
+ require 'zebra/zpl/qrcode'
18
+ require 'zebra/zpl/justification'
19
+ require 'zebra/zpl/raw'
@@ -27,7 +27,7 @@ module Zebra
27
27
  end
28
28
 
29
29
  def print_density=(d)
30
- raise InvalidPrintDensityError unless (0..6).include?(d)
30
+ raise InvalidPrintDensityError unless (0..15).include?(d)
31
31
  @print_density = d
32
32
  end
33
33
 
@@ -10,6 +10,10 @@ module Zebra
10
10
 
11
11
  attr_reader :scale_factor, :correction_level
12
12
 
13
+ def width=(width)
14
+ @width = width || 0
15
+ end
16
+
13
17
  def scale_factor=(value)
14
18
  raise InvalidScaleFactorError unless (1..99).include?(value.to_i)
15
19
  @scale_factor = value
@@ -22,7 +26,7 @@ module Zebra
22
26
 
23
27
  def to_zpl
24
28
  check_attributes
25
- ["b#{x}", y, "Q", "s#{scale_factor}", "e#{correction_level}", "\"#{data}\""].join(",")
29
+ "^FW#{rotation}^FO#{x},#{y}^BQN,2,#{scale_factor},,3^FD#{correction_level}A,#{data}^FS"
26
30
  end
27
31
 
28
32
  private
@@ -0,0 +1,25 @@
1
+ require "zebra/zpl/printable"
2
+
3
+ module Zebra
4
+ module Zpl
5
+ class Raw
6
+ include Printable
7
+
8
+ attr_reader :width
9
+
10
+ def width=(width)
11
+ unless margin.nil? || margin < 1
12
+ @width = (width - (margin * 2))
13
+ else
14
+ @width = width || 0
15
+ end
16
+ end
17
+
18
+ def to_zpl
19
+ # check_attributes
20
+ "^FW#{rotation}^FO#{x},#{y}#{data}^FS"
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -5,7 +5,7 @@ module Zebra
5
5
  class Text
6
6
  include Printable
7
7
 
8
- attr_reader :font_size, :font_type, :width
8
+ attr_reader :font_size, :font_type, :width
9
9
 
10
10
  def font_size=(f)
11
11
  FontSize.validate_font_size f
@@ -1,5 +1,5 @@
1
1
  module Zebra
2
2
  module Zpl
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.5"
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
+ # lib = File.expand_path('../lib', __FILE__)
3
+ # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
5
  require 'zebra/zpl/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
@@ -19,9 +20,9 @@ Gem::Specification.new do |spec|
19
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.add_dependency "cups"
23
+ # spec.add_dependency "cups"
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "bundler", ">= 1.3"
25
26
  spec.add_development_dependency "rake"
26
27
  spec.add_development_dependency "rspec"
27
28
  spec.add_development_dependency "guard"
metadata CHANGED
@@ -1,41 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zebra-zpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barnabas Bulpett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: cups
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '1.3'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '1.3'
41
27
  - !ruby/object:Gem::Dependency
@@ -124,6 +110,7 @@ files:
124
110
  - lib/zebra/zpl/print_mode.rb
125
111
  - lib/zebra/zpl/printable.rb
126
112
  - lib/zebra/zpl/qrcode.rb
113
+ - lib/zebra/zpl/raw.rb
127
114
  - lib/zebra/zpl/rotation.rb
128
115
  - lib/zebra/zpl/text.rb
129
116
  - lib/zebra/zpl/version.rb
@@ -156,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
143
  - !ruby/object:Gem::Version
157
144
  version: '0'
158
145
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.6.10
146
+ rubygems_version: 3.0.6
161
147
  signing_key:
162
148
  specification_version: 4
163
149
  summary: Simple DSL to create labels and send them to a Zebra printer using Ruby,