2016-04-24 32 views
3

我想使用gem Prawn在Rails 4中生成横向格式的PDF文件。我在手册中阅读了以下选项,它工作正常。rails 4-使用新控制器的Gem prawn pdf景观渲染

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

但是,我想要写在应用程序/ PDF文件/ student_voucher_pdf.rb单独的控制器“StudentVoucherPdf”所有的渲染代码,我致电该控制器为:

pdf = StudentVoucherPdf.new(@student) 

现在我不能找出我应该给的地方:page_layout =>:landscape命令。请帮助。如果您需要了解其他任何事情,请询问。

回答

2

尝试降落您StudentVoucherPdfPrawn::Document,所以你可以使用PDF codument的方法从自身:

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

谢谢主席先生..你是爱.. <3 –