2

I'm having some trouble while trying to generate an pdf through the pdf_from_url method on production. The error is the following:

Error: PDF could not be generated!
 Command Error: /app/vendor/bundle/ruby/2.5.0/gems/wkhtmltopdf-binary-edge-0.12.5.0/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

The line bellow throws the error above:

   pdf = WickedPdf.new.pdf_from_url("https://google.com", {:temp_path => Rails.root.join('public')})

The error only occurs on production. Everything works normaly on development.

Running wkhtmltopdf https://google.com test.pdf via command line on the server works normally.

One thing to notice is that my application server runs on a dokku container, which i'm inexperienced in. So, probably the error occurs due to the way of how dokku's file architeture works.

What i have already tried:

  1. Changed wkhtmltopdf's gem from wkhtmltopdf-binary to wkhtmltopdf-binary-edge
  2. Installed libpng12 manualy on the server (not on dokku container)

What i'm using currently:

wicked_pdf gem version: 1.1.0

whtmltopdf [provider gem]: wkhtmltopdf-binary-edge ~> 0.12.5

platform/distribution and version: Dokku container running on Ubuntu 18.04

Lucas Vieira
  • 96
  • 2
  • 8

3 Answers3

1

I managed to solve that problem by using dokku-apt plugin to install the libpng12.

First, install the dokku-apt plugin on your dokku container:

sudo dokku plugin:install https://github.com/F4-Group/dokku-apt

Then, create a file named apt-packages on your root project directory and insert the name of the lib like:

libpng12-0

After that, create another file named apt-repositories on your root project directory and insert the following line to update your repositories: (remember to leave an empty line on the end of the file)

deb http://security.ubuntu.com/ubuntu xenial-security main

At last, commit and deploy those files to your dokku container and it should work.

Lucas Vieira
  • 96
  • 2
  • 8
1

I managed to solve such by installing libpng12-0 from a deb file.

wget -q -O libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb && sudo dpkg -i libpng12.deb && rm libpng12.deb

Chal13W1zz
  • 41
  • 3
0

for ubuntu 18.04 you should try

https://github.com/rposborne/wkhtmltopdf-heroku

(even though it says heroku ,it should work for most ubuntu 18.04 environments)

wkthmltopdf-binary-edge is not meant to be used outside of dev environments.

if the heroku gem doesn't work for you you could try to downgrade wkhtmltopdf-binary-edge to 0.12.4 or 0.12.3. I believe 0.12.5 binary has some issues with 18.04.

Yurui Zhang
  • 2,230
  • 16
  • 16
  • Thank you for your reply. I've tried changing to the `wkhtmltopdf-heroku` gem, but it throws the error above: `Failed to execute: ["/app/vendor/bundle/ruby/2.5.0/bin/wkhtmltopdf", "-q", "https://google.com", "/app/public/wicked_pdf_generated_file20190918-9-d35rl0.pdf"] Error: PDF could not be generated! Command Error: QSslSocket: cannot resolve CRYPTO_num_locks QSslSocket: cannot resolve CRYPTO_set_id_callback QSslSocket: cannot resolve CRYPTO_set_locking_callback QSslSocket: cannot resolve sk_free QSslSocket: cannot resolve sk_num (...)` – Lucas Vieira Sep 18 '19 at 16:44
  • That's odd. It looks like a SSL problem. Could you try to generate a pdf from a local html file? – Yurui Zhang Sep 18 '19 at 17:10
  • I created a simple html file to test that. It worked normally. Also works fine with the `pdf_from_string` method. Any ideas on how to fix that SSL problem? – Lucas Vieira Sep 18 '19 at 17:45
  • Apparently this error should be fixed in wkhtmltopdf's 0.12.5 version acording to wkhtmltopdf's [issue #3001](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001). – Lucas Vieira Sep 18 '19 at 18:24
  • You could try to reinstall the libssl package in your environment. Otherwise, try lower versions of wkhtmltopdf – Yurui Zhang Sep 18 '19 at 19:11
  • I have tried lower versions of wkhtmltopdf, they also throw this error. Reinstall the libssl package could be a fix, but i don't know how to do that on an dokku container. Could you give me some directions? – Lucas Vieira Sep 18 '19 at 19:24
  • Hi @LucasVieira Sorry I'm not familiar with Dokku :/ however if you have access to your `Dockerfile` you should be able to install additional packages with `apt-get` command. see https://stackoverflow.com/questions/40273087/how-to-install-multiple-packages-using-apt-get-via-a-dockerfile – Yurui Zhang Sep 18 '19 at 21:29
  • 1
    Thank you for your help. I managed to solve the problem by using [dokku-apt](https://github.com/F4-Group/dokku-apt) plugin to install the libpng12 package on my dokku container. – Lucas Vieira Sep 19 '19 at 15:12