Soh*_*lam 2 pdf ruby-on-rails prawn
我想在 Rails 4 中使用 gem Prawn 生成横向格式的 PDF 文件。我在手册中阅读了以下选项,效果很好。
pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
Run Code Online (Sandbox Code Playgroud)
但是,我想在 apps/pdfs/student_voucher_pdf.rb 中的单独控制器“StudentVoucherPdf”中编写所有渲染代码,并且我将此控制器称为:
pdf = StudentVoucherPdf.new(@student)
Run Code Online (Sandbox Code Playgroud)
现在我无法弄清楚应该在哪里给出 :page_layout => :landscape 命令。请帮忙。如果您需要了解任何其他事情,请询问。
尝试StudentVoucherPdf从下降Prawn::Document,这样您就可以使用 pdf codument 本身的方法:
class StudentVoucherPdf < Prawn::Document
def initializer student
@student = student
super :page_size => "A4", :page_layout => :landscape
end
end
Run Code Online (Sandbox Code Playgroud)