barcorde generation from out of the controller

102 views
Skip to first unread message

Oscar

unread,
Jul 29, 2013, 4:30:08 AM7/29/13
to ruby-...@googlegroups.com
I'm able to generate code39 barcode within from controller with the code:

pdf = Prawn::Document.new

        barcode = Barby::Code39.new @order.order_number
        barcode.annotate_pdf(pdf, :height => 30)

        pdf.text @order.order_number

        send_data pdf.render

Now, I changed controller so it will invoke ruby code:

format.pdf do
        pdf = InvoicePdf.new(@order, view_context)

        send_data pdf.render, filename: "invoice_#{@order.order_number}.pdf",
                              type: "application/pdf",
                              disposition: "inline",
                              size: 10
      end

So, my invoice_pdf.rb:

require 'barby'
require 'barby/barcode/code_39'
require 'barby/outputter/prawn_outputter'

class InvoicePdf < Prawn::Document
def initialize(order, view)
super({
:top_margin => 70,
:page_size => 'A4',
:font_size => 10,
:text  => 8
})

barcode_gen
end

def barcode_gen
barcode = Barby::Code39.new @order.order_number
barcode.annotate_pdf(XXXX, :height => 30)

end

end

How should I change the XXXX in this case?

Oscar

unread,
Jul 30, 2013, 1:05:29 AM7/30/13
to ruby-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages