Labels

A RubyGem for creating mailing, shipping, address, barcode and other labels and rendering as PDF's.

Features:

  • Design mailing, shipping, address, barcode and other labels!
  • Definition of label layout and design using XML
  • Support for different layer elements (shape, text, image, barcode, date) and layer ordering
  • Dynamic replacement of layer content by providing layer data
  • Rendering (and printing) of label documents as PDF

Installation

Labels is a RubyGem and can be installed using:

$ gem install labels

Layout / Design

Labels uses a special XML document type to define label layouts and data. It parses XML documents of this type and creates PDF renderings of the document.

See example/label.xml for an example label document and dtd/label.dtd for the XML document type definition.

Usage

The simplest way to use the Labels library is to open an existing label XML file and render the file to PDF:

label = Labels.open('/path/to/file.xml')
label.to_pdf('/path/to/output.pdf')

To save the document back to XML just do:

label.to_file('/path/to/file.xml')

You can also parse a raw labels XML string:

xml = '<?xml...>'

label = Labels.parse(xml)
label.to_pdf('/path/to/output.pdf')

Label documents can also be created using the Labels library:

document = Labels::Document.new

paper = Labels::Paper.new(Labels::Paper::LETTER)
paper.width = 200
paper.height = 1000

template = Labels::Template.new
template.title = 'My cool template'
template.columns = 3
template.rows = 4
template.width = 100
template.height = 100

shape = Labels::Shape.new
shape.width = 40
shape.height = 50
shape.fill = true
shape.fill_color = '777777'

document.paper = paper
document.template = template
document.layers = [shape]

document.to_file('/path/to/label.xml')
document.to_pdf('/path/to/label.pdf')

See the API documentation for more information...

Command Line

Labels also provides a command line tool for rendering label XML files:

$ labels -h
Usage: labels [OPTIONS] source target

    -v, --version
    -h, --help

Example:

$ labels ./path/to/label.xml ./path/to/output.pdf

License

MIT License. See LICENSE file for details.