Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Prawn/Labels: A simple helper to generate labels for Prawn PDFs

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 COPYING
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 prawn-labels.gemspec

Prawn/Labels: Label generator for Prawn PDFs

Prawn/Labels takes the guess work out of generating labels using Prawn >= 0.12.0


Using RubyGems

$ gem install prawn-labels

Using Bundler

gem "prawn-labels"


We've tried to make generating labels as simple as possible with Prawn::Labels. If you have an object which responds to each, then you're in business.

Create and save a PDF file

require 'prawn/labels'

names = ["Jordan", "Chris", "Jon", "Mike", "Kelly", "Bob", "Greg"]

Prawn::Labels.generate("names.pdf", names, :type => "Avery5160") do |pdf, name|
  pdf.text name

This creates a document with a name from the names array in each label. The labels will be formatted for Avery 5160 labels. Formats are defined in the prawn/labels/types.yaml file, or by loading a custom hash or yaml file

For a full list of examples, take a look in the examples folder.

Render a PDF file and send to browser

labels = Prawn::Labels.render(names, :type => "Avery5160") do |pdf, name|
  pdf.text name

send_data labels, :filename => "names.pdf", :type => "application/pdf"

Scale text to fit label

Prawn::Labels.generate( "names.pdf", names, :type => "Avery5160",
                        :shrink_to_fit => true) do |pdf, name|
  pdf.text name

Custom label types

If the label type you need to use isn't defined in prawn/labels/types.yaml file, you can define and load your own.

Prawn::Labels.types = '/path/to/custom/types.yaml'

Prawn::Labels.generate("names.pdf", names, :type => "Custom123") do |pdf, name|
  pdf.text name

or using a hash:

Prawn::Labels.types = {
  "QuarterSheet" => {
    "paper_size" => "A4",
    "columns"    => 2,
    "rows"       => 2

Prawn::Labels.generate("names.pdf", names, :type => "QuarterSheet") do |pdf, name|
  pdf.text name

Prawn document options

Prawn::Labels allows passing a hash of document options all the way through to Prawn.

require 'prawn/labels'

names = ["Jordan", "Chris", "Jon", "Mike", "Kelly", "Bob", "Greg"]

Prawn::Labels.generate("names.pdf", names, type: "Avery5160", document: { page_layout: :landscape }) do |pdf, name|
  pdf.text name

Other document properties that can be set via this hash can be found in the Prawn Documentation


Something went wrong with that request. Please try again.