gpt4 book ai didi

ruby-on-rails - Rails 4-Gem prawn 使用新 Controller 进行 pdf 景观渲染

转载 作者:行者123 更新时间:2023-12-02 21:04:24 25 4
gpt4 key购买 nike

我想在 Rails 4 中使用 gem Prawn 生成横向格式的 PDF 文件。我在手册中阅读了以下选项,效果很好。

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

但是,我想在 apps/pdfs/student_voucher_pdf.rb 中的单独 Controller “StudentVoucherPdf”中编写所有渲染代码,并且我将此 Controller 称为:

pdf = StudentVoucherPdf.new(@student)

现在我无法弄清楚应该在哪里给出 :page_layout => :landscape 命令。请帮忙。如果您需要了解任何其他信息,请询问。

最佳答案

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

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

关于ruby-on-rails - Rails 4-Gem prawn 使用新 Controller 进行 pdf 景观渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com