rails4-Gem大虾使用新控制器渲染pdf风景

rails 4- Gem prawn pdf landscape rendering using new controller

我想使用 gem Prawn in Rails 生成横向格式的 PDF 文件 4. 我在手册中阅读了以下选项,它工作正常。

pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)

但是,我想在 apps/pdfs/student_voucher_pdf.rb 中的单独控制器 "StudentVoucherPdf" 中编写所有渲染代码,我将此控制器称为:

pdf = StudentVoucherPdf.new(@student)

现在我想不出我应该在哪里给出 :page_layout => :landscape 命令。请帮忙。如果您需要了解任何其他内容,请询问。

尝试从 Prawn::Document 继承您的 StudentVoucherPdf,这样您就可以使用 pdf 文档本身的方法:

class StudentVoucherPdf < Prawn::Document
   def initializer student
      @student = student
      super :page_size => "A4", :page_layout => :landscape
   end
end