[英]Generating pdf in rails 4 app using PDFKit and wkhtmltopdf
我在rails应用程序上有一个现有的ruby,我想生成特定视图页面的pdf。 我在我的系统中安装了wkhtmltopdf和pdfkit。 我正在使用Windows 8.1 64位版本,我正在关注Ryan Bate的rails for pdfkit教程。 教程链接在这里: -
http://railscasts.com/episodes/220-pdfkit?autoplay=true
我的config \\ initializers \\ pdfkit.rb文件如下: -
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
现在,当我要通过在URL末尾附加.pdf打开浏览器上的视图文件时,我收到以下错误:
命令失败(exitstatus = 1):C:\\ RailsInstaller \\ wkhtmltopdf \\ bin \\ wkhtmltopdf.exe --page-size法律--print-media-type - -
例如,我的一篇文章的URL是:
现在当我输入http:// localhost:3000 / articles / 9.pdf时 ,我收到上述错误。
请帮我搞清楚。
提前致谢!!!
您可能需要告诉Rails使用PDFKit中间件。 config\\initializers\\pdfkit.rb
文件应如下所示:
PDFKit.configure do |config|
...
end
require "pdfkit"
Rails.application.config.middleware.use PDFKit::Middleware, print_media_type: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.