mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.52k stars 640 forks source link

wicked_pdf due to wkhtmltopdf not finding OpenSSL 1.1 despite installing over OpenSSL 3 #1114

Closed AndyObtiva closed 1 month ago

AndyObtiva commented 2 months ago

Issue description

After we upgraded our Rails 7 app to Ruby 3.1 and OpenSSL 3 in our build server, we are having an issue when using our Rails app to generate a PDF where wicked_pdf somehow fails due to expecting OpenSSL 1.1.

RuntimeError Failed to execute:
["/usr/bin/wkhtmltopdf", "--orientation", "Portrait", "--page-size", "Letter", "--margin-top", "45", "--header-html", "file:////tmp/wicked_header_pdf20240416-1-cz41ln.html", "file:////tmp/wicked_pdf20240416-1-g5no29.html", "/tmp/wicked_pdf_generated_file20240416-1-8tyx4w.pdf"]
Error: PDF could not be generated!
 Command Error: pid 49 exit 127
Error loading shared library libssl.so.1.1: No such file or directory (needed by /usr/bin/wkhtmltopdf)
Error loading shared library libcrypto.so.1.1: No such file or directory (needed by /usr/bin/wkhtmltopdf)

We are installing wkhtmltopdf as a prerequisite from a Docker image (madnight/docker-alpine-wkhtmltopdf).

Expected or desired behavior

We expect wicked_pdf to work normally with our Docker image that has OpenSSL3 and Ruby 3.1 instead of OpenSSL 1.1 and Ruby 2.7

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf):

    wicked_pdf (2.7.0)
  wicked_pdf (~> 2.6, >= 2.6.3)

wkhtmltopdf version (output of wkhtmltopdf --version):

Version 0.12.5, which comes with the Docker image madnight/docker-alpine-wkhtmltopdf

whtmltopdf provider gem and version if one is used:

We don't use wkhtmltopdf-binary.

platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar):

Alpine Linux: ruby:3.1-alpine

--

We just tried relying on wkhtmltopdf-binary instead of the wkhtmltopdf library in the Docker image to fix the issue and our web server kept crashing upon accessing PDF URLs that use wicked_pdf.

Is there a way to make wicked_pdf work with OpenSSL3 using wkhtmltopdf? If not, can wicked_pdf work with an alternative low-level PDF library that is compatible with OpenSSL 3, like puppeteer perhaps?

aarestad commented 1 month ago

We are hitting this too, using the ruby:3.3.1 Docker image (aka 3.3.1-bookworm). I found a related issue on StackOverflow and think I'll try the recommended path of grabbing libssl manually.

kimesf commented 1 month ago

You have to use the binary built against Debian bookworm. It works with OpenSSL3.

wkhtmltopdf_binary gem still don't support it (see https://github.com/zakird/wkhtmltopdf_binary_gem/issues/162).

The package can be downloaded from Github (see https://github.com/wkhtmltopdf/packaging/issues/155).

Get the binary from the package and setup the project to use it with something like this:

# config/initializers/wicked_pdf.rb
WickedPdf.config = {
  exe_path: Rails.root.join("bin", "wkhtmltopdf-amd64").to_s, # or wherever you put it
  enable_local_file_access: true
}
patricksimpson commented 1 month ago

Hit this issue as well. We we're able to install the libssl manually and get past it.

RUN wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb
RUN dpkg -i libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb

Edit: I don't think this workaround is ideal.

patricksimpson commented 1 month ago

Also changing our base to FROM ruby:3.3.1-bullseye works for us.

kimesf commented 1 month ago

wkhtmltopdf_binary is now supporting Debian 12 on 0.12.6.7 :tada:

I think this can be closed btw

unixmonkey commented 1 month ago

@AndyObtiva Let me know if this solves your problem or not please. Feel free to reopen if it doesn't. Thank you.

AndyObtiva commented 1 month ago

My OS is Alpine Linux (ruby:3.1-alpine as mentioned in the issue description body), not Debian 12. But, we stumbled upon a workaround that is good enough for now. If we decide to do an upgrade in the future, I will let you know if wkhtmltopdf_binary would not work.

Thank you.