保存 PDFKit 中间件显示的 PDF 文件 [英] Save PDF file shown by PDFKit middleware

查看:56
本文介绍了保存 PDFKit 中间件显示的 PDF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人有兴趣将 PDF 文件保存在 PDFKit 中间件 gem 显示的文件系统中,那么这里是...

If somebody is interested in saving the PDF file in the filesystem which is shown by PDFKit middleware gem, then here it is...

  1. 覆盖 middleware.rb 文件的 call 方法.
  2. 在覆盖时只替换这一行:

  1. Override the call method of middleware.rb file.
  2. In overriding just replace this line:

body = PDFKit.new(translate_paths(body, env), @options).to_pdf

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

如果您不想给出 pdf 响应,也可以覆盖 response-body 和 content-type.如果您有任何进一步的查询,请继续.

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.

这个过程真的很有帮助,因为当你的视图文件中有大量的 JavaScript 和 CSS 时,render_to_string 方法将不起作用,即它不会渲染大量的 JavaScript.

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.

推荐答案

如果有人有兴趣将 PDF 文件保存在 PDFKit 中间件 gem 显示的文件系统中,那么这里是...

If somebody is interested in saving the PDF file in the filesystem which is shown by PDFKit middleware gem, then here it is...

  1. 覆盖 middleware.rb 文件的 call 方法.
  2. 在覆盖时只替换这一行:

  1. Override the call method of middleware.rb file.
  2. In overriding just replace this line:

body = PDFKit.new(translate_paths(body, env), @options).to_pdf

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

如果您不想给出 pdf 响应,也可以覆盖 response-body 和 content-type.如果您有任何进一步的疑问,请继续.

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.

这个过程真的很有帮助,因为当你的视图文件中有大量的 JavaScript 和 CSS 时,render_to_string 方法将不起作用,即它不会渲染大量的 JavaScript.

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.

这篇关于保存 PDFKit 中间件显示的 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆