Rails、Prawn - PDF 显示在浏览器中ETC
我正在尝试理解 Prawn pdf gem。
我能够让它生成一个pdf文件。 gemfile 中的每个 gem 都包含:
gem 'mysql', '~> 2.8.1'
gem 'prawn', '~> 0.12.0'
gem 'pdf-reader', '~> 0.10.0'
gem 'Ascii85', '~> 1.0.1'
在 config/application.rb 中:
config.autoload_paths << "#{Rails.root}/app/reports"
然后在控制器中:
require 'prawn'
def index
pdf = Prawn::Document.new
pdf.text "Hello World"
pdf.render_file "x.pdf"
end
然后我调用索引函数。在我的应用程序的根目录中创建了一个名为 x.pdf 的 PDF。其中包括 gemfile、rakefile 和 config.ru。
问:
- 如何强制虾在app/report(或任何其他选定的)文件夹中生成文件?
- 如何在浏览器窗口中执行生成文件的操作而不保存它?
- 如何使其保存并显示在浏览器窗口中?
I'm trying to understand the Prawn pdf gem.
I was able to make it generate a pdf. Every gem in the gemfile included:
gem 'mysql', '~> 2.8.1'
gem 'prawn', '~> 0.12.0'
gem 'pdf-reader', '~> 0.10.0'
gem 'Ascii85', '~> 1.0.1'
In the config/application.rb:
config.autoload_paths << "#{Rails.root}/app/reports"
Then in the controller:
require 'prawn'
def index
pdf = Prawn::Document.new
pdf.text "Hello World"
pdf.render_file "x.pdf"
end
Than I call the index function. A PDF named x.pdf is created in the root of my application. Amongst the gemfile, rakefile and config.ru.
Question:
- How can I force prawn to generate the file in the app/report (or any other selected) folder?
- How can I make the action to generate the file in the browser window and don't save it?
- How can I make it to save and show up in the browser window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何强制虾在app/report(或任何其他选定的)文件夹中生成文件?
如何在浏览器窗口中执行生成文件的操作而不保存它?
如何使其保存并显示在浏览器窗口中?
How can I force prawn to generate the file in the app/report (or any other selected) folder?
How can I make the action to generate the file in the browser window and don't save it?
How can I make it to save and show up in the browser window?
回答问题3:“如何才能保存并显示在浏览器窗口中?”
disposition: 'inline'
将强制浏览器(如果可以的话)在当前浏览器窗口内显示您的 PDFAnswering Question 3: "How can I make it to save and show up in the browser window?"
disposition: 'inline'
will force the browser ( if it can ) to display your PDF inside the current browser window试试这个:
也就是说,除了一个简单的 PDF 之外,您可能希望在控制器外部的某个地方生成它。
Try this:
That said, for anything but a trivial PDF you will probably want to generate it outside the controller somewhere.