EDIT
In your InvoicePdf
class, change the barcode
method to:
def barcode
barcode = Barby::Code39.new @order.order_number
barcode.annotate_pdf(self)
end
The annotate_pdf
method takes a Prawn::Document
as its argument, which is self
here.
Original Answer
If you want to create a new pdf with your barcode, you can just do:
def barcode
_barcode = Barby::Code39.new(@order.order_number)
outputter = Barby::PrawnOutputter.new(_barcode)
outputter.to_pdf
end
Note that you can specify pdf options (including height, margins, page size, etc.) on the new PrawnOutputter
or on the to_pdf
call. See the documentation for more details: https://github.com/toretore/barby/wiki/Outputters and http://rdoc.info/github/toretore/barby/Barby/PrawnOutputter.
And if you want to write it to a file do:
File.open("my_file.pdf","w") { |f| f.print barcode }
Note that you can also just call _barcode.to_pdf
, which seems to have the same effect as creating a new PrawnOutputter
, but this functionality is not described in the Barby documentation.
If you have an existing pdf document (as a Prawn::Document
) that you want to write a barcode to, note that you could do:
def barcode(p_pdf)
_barcode = Barby::Code39.new(@order.order_number)
_barcode.annotate_pdf(p_pdf)
end