Friday, August 21, 2015

Fix for Bad wkhtmltopdf's path: /usr/bin/wkhtmltopdf error when using wkhtmltopdf gem

If you're getting the error(see the image below) - Bad wkhtmltopdf's path: /usr/bin/wkhtmltopdf when using the wkhtmltopdf gem in your rails app to convert an HTML page to a PDF file. Following the below steps should help you get it working on your machine -

Bad wkhtmltopdf's path: /usr/bin/wkhtmltopdf

  • We need to first locate the bin file that converts HTML to pdf. This usually is present inside your wkhtmltopdf gem. For me this was located at - /Users/my_user_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/wkhtmltopdf-0.1.2/bin
  • If you're using a mac, you'd need the darwin version of the bin file. Do a sudo cp wkhtmltopdf_darwin_386 /usr/bin/wkhtmltopdf.
    • This copies the bin from within the gem directory to the location where all local system bin files are generally present.
    • Please note: If you're using the another OS, you'd need to copy the appropriate bin file wrt the OS that you're using.