def index
@forms = Form.all
respond_to do |format|
format.html
end
end
def submit
respond_to do |format|
format.pdf {render }
end
end
submit.pdf.prawn file
pdf.text "successfully submitted"
答案 0 :(得分:7)
Prawn可以生成并返回PDF而无需在本地保存...
def submit
send_data(generate_pdf, :filename => "output.pdf", :type => "application/pdf")
end
private
def generate_pdf
Prawn::Document.new do
text "Hello Stackoverflow"
end.render
end
答案 1 :(得分:0)
使用prawn生成保存在/ public文件夹中某处的pdf,如:
Prawn::Document.generate("#{RAILS_ROOT}/public/pdfs/myfile.pdf")
然后只需使用您的控制器将用户重定向到该位置:
redirect_to '/pdfs/myfile.pdf'