this is how i adapted user1632065 to work in html and pdf
in your gemfile
gem 'cairo' gem 'barby'
in your model
class ExampleModel def barcode require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/cairo_outputter' Barby::CairoOutputter.new(Barby::Code128B.new('bla bla this is barcode source')) end end
in your opinion (in my case haml)
%img{:width => ExampleModelObject.barcode.width, :src=> "data:image/svg+xml;base64,#{Base64.encode64(ExampleModelObject.barcode.to_svg)}"}
this way you get the correct barcode width
source share