1
votes

I have installed wicked_pdf locally to my Rails app and it is generating pdfs.

When I push it to Heroku and try to generate a pdf, I get:

Command Error: /app/bin/wkhtmltopdf: error while loading shared libraries: libwkhtmltox.so.0: cannot open shared object file: no such file or directory

I am running Arch. wkhtmltopdf was installed using pacman and generated entries in the /usr/bin/wkhtmltopdf and /usr/lib64/libwkhtmltox.so.0

wkhtmltopdf is copied to my_rails_app/bin/wkhtmltopdf and Heroku appears to find it ok.

libwkhtmltox.so.0 has been copied to three locations and Heroku still cannot find it.

  • my_rails_app/bin/libwkhtmltox.so.0
  • my_rails_app/lib/libwkhtmltox.so.0
  • my_rails_app/lib64/libwkhtmltox.so.0

    Where does Heroku want this file?

    -- EDIT --

    The test "wkhtmltopdf http://www.google.com google.pdf" performs as expected on my local machine (it generates a pdf file).

    Using "heroku run bash" brings up a command line connected to my heroku server;
    % which wkhtmltopdf
    => /app/bin/wkhtmltopdf

    % which libwkhtmltox.so.0
    => /app/bin/libwkhtmltox.so.0

    % wkhtmltopdf http://www.google.com google.pdf
    => wkhtmltopdf: error while loading shared libraries: libwkhtmltox.so.0: cannot open shared object file: No such file or directory

  • 2

    2 Answers

    1
    votes

    The issue seemed to be related to Heroku's use of containers and my cut and paste efforts moving symlinks not actual files (go figure). I would thank the minion at Arch who gave me the pointer I needed, but it included comments alluding to my greatly diminished mental capacity and surprise that I could even install Arch, let alone develop on it. So I'm a little reluctant to give him credit.

    As it was, with new info, my google foo found https://github.com/dscout/wkhtmltopdf-buildpack After removing my previous attempts at a fix and the arch pacman download, this buildpack worked where ruby gems and Arch pacman failed.

    I am now a happy idiot :-)

    1
    votes

    wicked_pdf gem is mainly dependententer link description here on binary 'wkhtmltopdf'

    In your local machine just execute command which wkhtmltopdf . It'll show you the path where it resides. in my case it resides at /usr/local/bin/wkhtmltopdf

    Next in your development application, check wicked_pdf.rb You must have defined the :exe_path to above location. Your syntax must be looking something like this :

    WickedPdf.config = {
      :exe_path => '/usr/local/bin/wkhtmltopdf'
    }
    

    When you move to heroku above binary and it's path configuration won't work.

    You have got two alternatives here:

    1st way: Source : This article.

    Create a bin folder in your application root directory and place the binary inside it. Your binary will reside at : project_root/bin/wkhtmltopdf-amd64

    Then link to :exe_path to this location.

    This might work(not tried though).

    Cons : Having binary files in project directory is not a good way. The better alternative is to place your binary in AWS or any cloud service & use the path location.

    2nd way: (I have implemented)

    I avoided having this binary in heroku & was not provided any access to cloud service. I Used wkhtmltopdf-heroku gem This gem internally uses the same binary(wkhtmltopdf). Check bin folder of this gem(holds the same library).

    Usage: Add following gems to Gemfile.

       gem 'wicked_pdf'
       gem 'wkhtmltopdf-heroku'
    
    
      config/initializers/wicked_pdf.rb
       #comment out all the :exe_path settings. 
       # our application will be using wkhtmltopdf-heroku gem
       #(which will handle the path settings)
    

    Rest of the Mime configuration & require statements will still work.

    It did work for me. Hope it helps you :)