Print labels with

Get Version 0.0.2

→ ‘printing_labels’

What

This gem want to help you in creating a pre-compiled pdf labels sheet. You can add text to a print queque, then using print method, you can genarate the pdf, defining a template for it, specifying layout of labels (columns, rows, label size, page margins, label margins etc). I’ve built it for a specific project and i develop a gem to share it, any comments are welcome.

Installing

sudo gem install printing_labels

The basics

Requiring the gem you can create a Label object and use its methods to create a printing queque and print the file.

Demonstration of usage

You need to create an object Label and store it in a session, put it in the base_controller.

require 'printing_labels'

class Admin::BaseController < ApplicationController
  before_filter :find_label_queque

private

def find_label_queque
  @queque = (session[:queque] ||= Label.new)
end

end

This is an Example of label_controller you can add and remove project from the printing queque, setting the pdf label sheets template specifying information about margins, label dimension, label margins, number of column, number of raw, text_size and line_height. You must insert parameters in millimeter.

class Admin::LabelsController < Admin::BaseController

  def add_to_print_queque
    @queque.add("Example Text") 
    render :update do |page|
      page.replace_html("show-queque-number", "A text is been added to print queque")  
    end    
  end

  def remove_from_print_queque
    @queque.remove("Example Text")
    render :update do |page|
      page.replace_html("show-queque-number", "A text is been removed from print queque");
    end
  end

  def print_labels
    @queque.startnumber = params[:start][:number]
    @queque.set_template(
                  :type => "Type A", 
                  :border => true, 
                  :n_row => 7, 
                  :n_col=> 2, 
                  :pm_top => 25, 
                  :pm_left => 5, 
                  :pm_bottom => 24,
                  :pm_right => 5.5, 
                  :l_width => 98, 
                  :l_height => 35.5,
                  :lm_left => 0, 
                  :lm_right => 0, 
                  :lm_top => 0, 
                  :lm_bottom => 0,  
                  :lm_inter => 2,
                  :label_padding => 8, 
                  :text_size => 14,
                  :line_height => 7)

    pdf = @queque.print
    send_data pdf.render, :filename => "labels.pdf", :type => "application/pdf" 
  end

end

If you want to add multi line text to the print queque you have to:

    @queque.add("Example Text\n second row\n third row") 

This is the way a pdf label sheet is compiled from left to right. The starting point let you to choose the starting label. If you want you can disable borders setting *border information to false.

pdf layout

Todo

This is the first release of the gem, now it works but it’s possible to tune it, i’m working on it if you are interested send me comment they are welcome!!

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

The trunk repository is svn://rubyforge.org/var/svn/printing_labels/trunk for anonymous access.

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to Duccio Giovanelli email. You can visit Rails on the road our Italian blog about rails

Extendi
Rails on the Road
Dr Nic, 12th June 2007
Theme extended from Paul Battley