我正在使用
Windows 7
Rails 3.2.11
wkhtmltopdf 0.9.9
在gem文件中
gem 'wicked_pdf'
在我的初始化程序中
WickedPdf.config = { :exe_path => 'C:\wkhtmltopdf' }
Exe位于
C:\wkhtmltopdf\wkhtmltopdf.exe
当我从 Rails c 运行时
irb(main):001:0> WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
我收到以下错误...
"*******\"C:\wkhtmltopdf\"
\"file:///C:/Users/bob/bob_rail s_demo/Course_Stats/wicked_pdf20130307-6328-7cuwz7.html\" \"C:/Users/bob/wful ts_rails_demo/Course_Stats/wicked_pdf_generated_file20130307-6328-n902yj.pdf\" * ******" RuntimeError: Failed to execute: "C:\wkhtmltopdf" "file:///C:/Users/bob/bob_rails_demo/Course_Stats/ wicked_pdf20130307-6328-7cuwz7.html" "C:/Users/bob/bob_rails_demo/Course_S tats/wicked_pdf_generated_file20130307-6328-n902yj.pdf" Error: Permission denied - "C:\wkhtmltopdf" "file:///C:/Users/bob/wful ts_rails_demo/Course_Stats/wicked_pdf20130307-6328-7cuwz7.html" "C:/Users/bob /bob_rails_demo/Course_Stats/wicked_pdf_generated_file20130307-6328-n902yj.pd f" from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/wicked_pdf-0.9 .4/lib/wicked_pdf.rb:50:inrescue in pdf_from_string' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/wicked_pdf-0.9 .4/lib/wicked_pdf.rb:34:in
pdf_from_string' from (irb):1 from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 1/lib/rails/commands/console.rb:47:instart' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 1/lib/rails/commands/console.rb:8:in
start' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 1/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:in
require' from script/rails:6:in `'
如果我将此行更改为...
WickedPdf.config = { :exe_path => 'C:\wkhtmltopdf\wkhtmltopdf.exe' }
然后在 Rails 命令行中运行它,它似乎可以工作,但在我的应用程序中,Rack 中间件只是挂起......
最佳答案
我遇到了同样的问题,除了最初我的 exe 位于 C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe
所以我将其更改为 C:\wkhtmltopdf\wkhtmltopdf.exe
(你已经有了),然后我将我的 :exe_path
设置为: :exe_path => 'C:\wkhtmltopdf\wkhtmltopdf.exe'
我相信您必须在 Windows 环境中添加 .exe 的原因是因为 Windows 需要显式指定文件路径。一旦我这样做了,它就像一个魅力。
让我知道进展如何(或进展如何)!
关于windows - 使用 wicked_pdf 拒绝权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283229/