保存PDFKit中间件显示的PDF文件
如果有人有兴趣将 PDF 文件保存在 PDFKit 中间件 gem 显示的文件系统中,那么这里是...
- 重写 middleware.rb 文件的
call
方法。 在重写中只需替换这一行:
body = PDFKit.new(translate_paths(body, env), @options).to_pdf
与
pdf = PDFKit.new(translate_paths(body, env), @options) file = pdf.to_file('您的/文件/名称/路径') Mymodel.my_method() #你可以在这里编写你的方法来使用该文件 body = pdf.to_pdf #这里可以更改响应正文
如果您不想给出 pdf 响应,您也可以覆盖响应正文和内容类型。如果您还有任何疑问,请继续。
这个过程确实很有帮助,因为当您的视图文件中包含大量 JavaScript 和 CSS 时,render_to_string
方法将不起作用,即它不会渲染大量 JavaScript。
If somebody is interested in saving the PDF file in the filesystem which is shown by PDFKit middleware gem, then here it is...
- Override the
call
method of middleware.rb file. In overriding just replace this line:
body = PDFKit.new(translate_paths(body, env), @options).to_pdf
with
pdf = PDFKit.new(translate_paths(body, env), @options) file = pdf.to_file('Your/file/name/path') Mymodel.my_method() #You can write your method here to use that file body = pdf.to_pdf #Here you can change the response body
You can also override the response-body and content-type if you don't want to give pdf response. If you have any further query then go ahead.
This procedure is really help full because when you are having heavy JavaScript an CSS in your view file then render_to_string
method will not work i.e. it will not render the heavy JavaScript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人有兴趣将 PDF 文件保存在 PDFKit 中间件 gem 显示的文件系统中,那么这里是...
call
方法。在重写中只需替换这一行:
与
如果您不想给出 pdf 响应,您也可以覆盖响应正文和内容类型。如果您还有任何疑问,请继续。
这个过程确实很有帮助,因为当您的视图文件中包含大量 JavaScript 和 CSS 时,
render_to_string
方法将不起作用,即它不会渲染大量 JavaScript。If somebody is interested in saving the PDF file in the filesystem which is shown by PDFKit middleware gem, then here it is...
call
method of middleware.rb file.In overriding just replace this line:
with
You can also override the response-body and content-type if you don't want to give pdf response. If you have any further query then go ahead.
This procedure is really help full because when you are having heavy JavaScript an CSS in your view file then
render_to_string
method will not work i.e. it will not render the heavy JavaScript.