ruby-on-railsrubywkhtmltopdfalpine-linuxwicked-pdf

Invalid platform error when using wkhtmltopdf in production


I have deployed an app that uses wicked-pdf for PDF generation, but I can't get it to work. My server uses ubuntu-20.04 and below is the error that I get (I use ruby:2.7.1-alpine)

/usr/local/bundle/gems/wkhtmltopdf-binary-0.12.6.6/bin/wkhtmltopdf:69:in `<main>': Invalid platform, must be running on Ubuntu 16.04/18.04/20.04/22.04, CentOS 6/7/8, Debian 9/10, Archlinux amd64, or Intel-based Cocoa macOS (missing binary: /usr/local/bundle/gems/wkhtmltopdf-binary-0.12.6.6/bin/wkhtmltopdf_alpine_3.12.0_amd64). (RuntimeError)

Solution

  • Fixed it by adding the following line to dockerfile:

    RUN apk --no-cache add wkhtmltopdf ttf-ubuntu-font-family
    

    And updating config/initializers/wicked_pdf.rb

    require "wicked_pdf"
    
    WickedPdf.config = {
      exe_path: '/usr/bin/wkhtmltopdf'
    }