我在互联网上四处寻找,但似乎找不到如何在rails中显示PDF(我只能找到如何创建PDF的信息).
有人知道我需要显示什么代码/Ruby 吗?
我在互联网上四处寻找,但似乎找不到如何在rails中显示PDF(我只能找到如何创建PDF的信息).
有人知道我需要显示什么代码/Ruby 吗?
在控制器中:
def pdf
pdf_filename = File.join(Rails.root, "tmp/my_document.pdf")
send_file(pdf_filename, :filename => "your_document.pdf", :type => "application/pdf")
end
config/environment/production.rb
年:
config.action_dispatch.x_sendfile_header = "X-Sendfile" # f或 apache
或
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # f或 nginx
The config modification is required because it enables the web server to send the file directly from the disk, which gives a nice perf或mance boost.
Update
如果要显示而不是下载,请使用send_file
的:disposition
选项:
send_file(pdf_filename, :filename => "your_document.pdf", :disposition => 'inline', :type => "application/pdf")
If you want to display it inline, this question will be much m或e complete that I could ever be.