Pass in single object instead of collection
dhulihan opened this issue · 3 comments
dhulihan commented
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
jordanbyron commented
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?
dhulihan commented
That's a very nice solution to what I was looking for. Thanks Jordan!
jordanbyron commented
My pleasure. Best of luck 😄