Module: ZplRenderer
- Defined in:
- lib/zpl_renderer.rb,
lib/zpl_renderer/binary.rb,
lib/zpl_renderer/engine.rb,
lib/zpl_renderer/errors.rb,
lib/zpl_renderer/decoder.rb,
lib/zpl_renderer/options.rb,
lib/zpl_renderer/version.rb,
lib/zpl_renderer/renderer.rb,
lib/zpl_renderer/sanitizer.rb,
lib/zpl_renderer/validation.rb
Overview
Offline ZPL to PNG/PDF converter for Ruby and Rails applications.
png = ZplRenderer.render(zpl, format: :png, width: 4, height: 6, dpi: 203)
ZplRenderer.render_file(zpl, "label.pdf", format: :pdf, dpi: 300)
Defined Under Namespace
Modules: Binary Classes: BinaryMissingError, ConfigurationError, Decoder, Engine, Error, InvalidBarcodeError, Options, OutputTooLargeError, RenderError, Renderer, Sanitizer, TimeoutError, UnsupportedCommandError, Validation, ValidationError
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.content_type(format) ⇒ Object
Content-Type helper for Rails send_data responses.
-
.decode_png(png_bytes) ⇒ Array<ZplRenderer::Decoder::Hit>
Decode barcodes/QR codes from a rendered PNG using an independent ZXing engine.
-
.render(zpl, **kwargs) ⇒ String
Render ZPL to binary PNG or PDF bytes.
-
.render_file(zpl, path, **kwargs) ⇒ String
Render ZPL and write the result to
path. -
.sanitize(zpl, canvas_dots: nil) ⇒ ZplRenderer::Sanitizer::Result
Sanitize carrier ZPL quirks (e.g. ^FO464,-- and narrow ^PW).
-
.validate(zpl, **kwargs) ⇒ ZplRenderer::Validation::Result
Validate ZPL without rendering.
Class Method Details
.content_type(format) ⇒ Object
Content-Type helper for Rails send_data responses.
68 69 70 |
# File 'lib/zpl_renderer.rb', line 68 def content_type(format) Options.new(format: format).content_type end |
.decode_png(png_bytes) ⇒ Array<ZplRenderer::Decoder::Hit>
Decode barcodes/QR codes from a rendered PNG using an independent ZXing engine.
75 76 77 |
# File 'lib/zpl_renderer.rb', line 75 def decode_png(png_bytes) Decoder.new.decode_png(png_bytes) end |
.render(zpl, **kwargs) ⇒ String
Render ZPL to binary PNG or PDF bytes.
35 36 37 |
# File 'lib/zpl_renderer.rb', line 35 def render(zpl, **kwargs) default_renderer.render(zpl, **kwargs) end |
.render_file(zpl, path, **kwargs) ⇒ String
Render ZPL and write the result to path.
42 43 44 |
# File 'lib/zpl_renderer.rb', line 42 def render_file(zpl, path, **kwargs) default_renderer.render_file(zpl, path, **kwargs) end |
.sanitize(zpl, canvas_dots: nil) ⇒ ZplRenderer::Sanitizer::Result
Sanitize carrier ZPL quirks (e.g. ^FO464,-- and narrow ^PW).
63 64 65 |
# File 'lib/zpl_renderer.rb', line 63 def sanitize(zpl, canvas_dots: nil) Sanitizer.sanitize(zpl, canvas_dots: canvas_dots) end |
.validate(zpl, **kwargs) ⇒ ZplRenderer::Validation::Result
Validate ZPL without rendering.
49 50 51 52 53 54 55 56 57 |
# File 'lib/zpl_renderer.rb', line 49 def validate(zpl, **kwargs) = Options.new(**kwargs) sanitized = Sanitizer.sanitize(zpl, canvas_dots: .sanitize_canvas_dots) result = Validation.new(sanitized.zpl, ).call sanitized.repairs.each do |repair| result.warnings << "sanitized #{repair[:from]} -> #{repair[:to]} (#{repair[:reason]})" end result end |