If someone is interested in saving a PDF file in a file system that is shown in PDFKit middleware gem format, then here ...
- Override the
call method of middleware.rb. When overriding, simply replace this line:
body = PDFKit.new(translate_paths(body, env), @options).to_pdf
from
pdf = PDFKit.new(translate_paths(body, env), @options) file = pdf.to_file('Your/file/name/path') Mymodel.my_method()
You can also override the response body and content type if you do not want to give the answer in pdf format. If you have another request, then continue.
This procedure is really complete, because when you have heavy JavaScript CSS in your view file, then the render_to_string method render_to_string not work, that is, it will not display heavy JavaScript.
ruby ruby-on-rails pdfkit
Ashish
source share