jordanbyron / prawn-labels

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass in single object instead of collection

dhulihan opened this issue · comments

I'd be interested in a feature that allows you to pass in a single object (instead of a collection that calls each), which is then duplicated to fill an entire sheet. What do you think?

require 'prawn/labels'

name = "Jordan"

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

Hey @dhulihan,

I think you could accomplish that with a little extra ruby code. Assuming the labels you are working with have 30 labels per page, like the Avery 5160s, you could just do this:

names = ["Jordan"] * 30

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

You could even get fancy and do it right in the generate method:

name = "Jordan"

Prawn::Labels.generate("names.pdf", [name] * 30, :type => "Avery5160") do |pdf, name|
  pdf.text name
end

Or get rid of the name variable entirely

Prawn::Labels.generate("names.pdf", ["Jordan"] * 30, :type => "Avery5160") do |pdf, name|
  pdf.text name
end

All accomplish the same thing. What do you think?

That's a very nice solution to what I was looking for. Thanks Jordan!

My pleasure. Best of luck 😄