简体   繁体   中英

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 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM