开发者

Rails generate barcodes from strings

What is the best way to generate barcodes from strings in a rails app? After displaying the codes in a view I also would like to print开发者_JS百科 them to a pdf file.

Thank you


I wanted to write this as a comment to idlefingers' answer, but apparently I don't have enough reputation to do that, so I'll write it here instead.

If you're creating PDFs you can use Barby to render the barcode directly into the PDF file instead of creating an image first:

require 'barby/outputter/prawn_outputter'
#aPdf is a Prawn::Document, aBarcode is a Barby::Barcode
aBarcode.annotate_pdf(aPdf, :x => 100, :y => 100)

There's also a PdfWriterOutputter.


When tasked with the same problem, I used barby to save the barcode as a png, then just loaded that into a pdf (using prawn). I don't know if it's the best way, but it works. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜