I have an existing ruby on rails app where I want to generate pdf of a particular view page. I have installed both wkhtmltopdf and pdfkit in my system. I am using windows 8.1 64bit version and I am following Ryan Bate's tutorial for pdfkit in rails. The tutorial link is here:-
http://railscasts.com/episodes/220-pdfkit?autoplay=true
My config\\initializers\\pdfkit.rb file is as:-
PDFKit.configure do |config|
config.wkhtmltopdf = 'C:\RailsInstaller\wkhtmltopdf\bin\wkhtmltopdf.exe'
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
}
# Use only if your external hostname is unavailable on the server.
config.root_url = "http://localhost"
config.verbose = false
end
Now when I am going to open the view file on the browser by appending .pdf at the end of URL, I am getting the following error:
command failed (exitstatus=1): C:\\RailsInstaller\\wkhtmltopdf\\bin\\wkhtmltopdf.exe --page-size Legal --print-media-type - -
For example, The URL of one of my article is :
http://localhost:3000/articles/9
Now when I am typing http://localhost:3000/articles/9.pdf , I am getting the above error.
Please help me to figure it out.
Thanks in advance!!!
You may need to tell Rails to use PDFKit middleware. The config\\initializers\\pdfkit.rb
file should look like this:
PDFKit.configure do |config|
...
end
require "pdfkit"
Rails.application.config.middleware.use PDFKit::Middleware, print_media_type: true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.