从我的控制器我创建pdf:
def show
@order = Order.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @order }
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
end
end
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
})
@order = order
@view = view
order_number
barcode
end
def order_number
text "Order #{@order.order_number}"
end
def barcode
barcode = Barby::Code39.new @order.order_number
barcode.annotate_pdf(XXXX)
end
end
我应该如何修改我的条形码方法或标记为XXXX的选项以将条形码嵌入 PDF 文档?