In a new app we are developing, we need to be able to dynamically create
a PDF and send it to the browser (inline with send_data). I have been
tinkering with PDF::Writer and love the simplicity and native ruby-ness
of it all.
However, one of the main uses for this functionality is to output a PDF
of addresses to be printed on Avery 5161 labels. LaTex seems to be
suited well for this, but it sure feels like the long way home getting
it all hooked up together.
My question is this: Is there a way to do this in PDF::Writer that I am
missing? If not, what is the best way to hook up LaTex to my rails app?
My question is this: Is there a way to do this in PDF::Writer that I am
missing? If not, what is the best way to hook up LaTex to my rails app?
Yes, there’s a way. No, it’s not “automatic” right now. If you’re
interested in taking the steps necessary to make PDF::Writer do the
right thing for labels, I’ll happily incorporate it into PDF::Writer.
Otherwise, it will have to wait until I have time to do it. There are
some examples in the open source world already (in other languages) on
how to best do this, and as long as it’s under the PDF::Writer licence
(essentially MIT-licensed, friendly to both open source and commercial
interests), I’ll incorporate it.
Thanks Austin - After a few hours of piddling this afternoon, I have PDF
Writer outputting my data into the right position for the labels we are
using. I hope to share the process once it is refined a little, nothing
to earth shattering, mostly using a ruler to plot out the key points
I am wondering if anyone has successfully worked around the UTF
limitation. We have accented characters that are my last hurdle to get
this thing working…
My question is this: Is there a way to do this in PDF::Writer that I am
missing? If not, what is the best way to hook up LaTex to my rails app?
Yes, there’s a way. No, it’s not “automatic” right now. If you’re
interested in taking the steps necessary to make PDF::Writer do the
right thing for labels, I’ll happily incorporate it into PDF::Writer.
Otherwise, it will have to wait until I have time to do it. There are
some examples in the open source world already (in other languages) on
how to best do this, and as long as it’s under the PDF::Writer licence
(essentially MIT-licensed, friendly to both open source and commercial
interests), I’ll incorporate it.
Hi Austin, Brad,
Has any progress / work been done on bringing easy label support to
PDF Writer? I can see that it was talked about here, and that labels
can be made with PDF Writer as is, but before I dive in and start
coding something I was wondering if anyone already was.
Right now I have an app that makes calles to glabel-batch (command
line gLabels) at its back end to print labels. The user can specify a
template created with gLabels (http://glabels.sourceforge.net/) and
then each time a record is added or updated a new label for it can be
printed. I’d like to remove my dependancy on gLabels (and more
importantly the dependancy on Gnome), since this is not really cross
platform. If no one else is on this I will probably setup a parser
for the gLabels XML format, that can be used in conjuntion with PDF
Writer. There is a lot of work that’s gone into the XML template
library in gLabels, and since sitting down with a ruler doesn’t appeal
to me, I think that bootstrapping a Ruby labelling solution to that
make a lot of since.
Thoughts?
Rob K.
catch(:end_of_labels) do
until elements.nil? do
label.across.times do |x|
label.down.times do |y|
e = elements.shift or throw :end_of_labels
pdf.y = pdf.absolute_top_margin - (y * vert_pitch)
pdf.text e, :left => (x * horiz_pitch)
end
end
pdf.start_new_page
end
end
pdf.render
end
end
I’m not sure if a catch/throw block is the nicest way to do that.
In my subscriber controller, I have a labels method for making the pdf:
def labels @subscribers = Subscriber.find_unexpired
send_data(PDF.labels(@subscribers.map {|s| s.shipping_label.join(“\n”)
}),
:filename => ‘windsor-review-subscriber-labels.pdf’,
:type => ‘application/pdf’,
:disposition => ‘inline’)
end
This is all pretty rough. It assumes that the lines on each label fit
in
the space (six lines of about 45 characters each). It does work,
though.
What information is in each gLabel template?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.