mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 646 forks source link

Runtime error on Windows 7 #402

Open abhishek77in opened 9 years ago

abhishek77in commented 9 years ago

Error is happening when render pdf: "pdf_name" is called inside the controller.

RuntimeError at /reports/1/print
Bad wkhtmltopdf's path: bundler: command not found: which
Install missing gem executables with `bundle install`

Gems I am using - rails 4.2, wkhtmltopdf-binary 0.9.9.3, wicked_pdf 0.11.0. I have tried upgrading gem to latest version pointing to Github master branch but that doesn't help.

wkhtmltopdf binary

abhishek77in commented 9 years ago

As per my investigation

(defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp

will always throw Runtime Error on windows machine as which command does not exist on windows. Since it's not a Exception it doesn't get caught and is not ignored. wicked_pdf.rb line no. 330

unixmonkey commented 9 years ago

If you add the :exe_path to your initializer, and it will never try to find out where wkhtmltopdf is installed, and never hit that which.

Still a valid issue that we shouldn't check for that on Windows, so I'll leave this open, but the above should get things working for you.

abhishek77in commented 9 years ago

The issue happens even when I am using wkhtmltopdf-binary gem and I don't think I need to set :exe_path in this case.

You are right if :exe_path is set which doesn't get called.

unixmonkey commented 9 years ago

It used to be that you had to set :exe_path always, but someone sent a pull request that tried to figure it out if you didn't set it up (which includes using which). You should set :exe_path and save yourself the headaches, or send a pull request to find the binary on Windows.

m-baumgartner commented 9 years ago

Or you could install the windows port of the which command. Here. More a workaround than a true platform-agnostic fix but still, worked for me.