fbpx

Using Wicked PDF gem in rails in a docker container

When you need to generate a PDF in your rails application the wicked PDF gem is great and easy to use. But requires the wkhtmltopdf binary to run. If you are running you rails app in a docker container be sure to use the linux binary. Go to https://wkhtmltopdf.org/downloads.html and download the linux 64-bit binary to your rails bin directory. Open bash in your docker container and cd into the bin directory:

docker-compose run app bash
cd bin

Then uncompress your binary:

tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

Reference the new binary for your development environment in the initializer:

if Rails.env.production?
  wkhtmltopdf_path = "#{Rails.root}/bin/wkhtmltopdf-prod"
else
  wkhtmltopdf_path = "#{Rails.root}/bin/wkhtmltox/bin/wkhtmltopdf"            
end