我在我的rails应用程序上使用pdfkit(我根据Ryan Bates railscast执行了此操作) 当前它在浏览器中显示pdf。下载pdf,而不是在浏览器中显示它
如何下载pdf?
感谢
编辑:
感谢您的答复!
但是我怎样才能在控制器中创建pdf的数据?
当url有.pdf
时,pdf自动显示。例如去这个链接时:
http://localhost:3000/home/index.pdf
它打开了页面的PDF版本会自动在浏览器上(这是一个轨道中间件设置)。
我在我的rails应用程序上使用pdfkit(我根据Ryan Bates railscast执行了此操作) 当前它在浏览器中显示pdf。下载pdf,而不是在浏览器中显示它
如何下载pdf?
感谢
编辑:
感谢您的答复!
但是我怎样才能在控制器中创建pdf的数据?
当url有.pdf
时,pdf自动显示。例如去这个链接时:
http://localhost:3000/home/index.pdf
它打开了页面的PDF版本会自动在浏览器上(这是一个轨道中间件设置)。
尝试使用send_data所有轨道控制器都有的方法。
事情是这样的:
# Generate a PDF document with information on the client and return it.
# The user will get the PDF as a file download.
def download_pdf
send_data(generate_pdf, :filename => "my_file.pdf", :type => "application/pdf")
end
假设这一个简单的机架终点:
class PdfEndpoint
def call(env)
[200, {"Content-Type" => "application/pdf", "Content-Disposition" => "attachment", "filename" => "filename.pdf"}, pdf_data]
end
end
还有以下Railscast可能会帮助:
我编辑了这个问题。 – 2011-12-16 18:14:21
心中已经编辑这个问题。 – 2011-12-16 18:14:07