wkhtmltopdf_binary_gem: doesn't work on Alpine

I’m using docker image ruby:2.6.3-alpine and this gem didn’t work. To work, you have to install by apk add wkhtmltopdf

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (3 by maintainers)

Most upvoted comments

This works for me in alpine 3.18 without using the binary gem:

############################ wkhtmltopdf binary ###############################
FROM surnet/alpine-wkhtmltopdf:3.18.0-0.12.6-small as wkhtmltopdf

############################ COPY APPLICATION FILES ###############################
FROM ruby:3.2.2-alpine as production
ARG RAILS_ENV='production'

ENV RAILS_ENV=$RAILS_ENV
ENV RAKE_ENV=$RAILS_ENV

RUN apk add --update 
                     fontconfig \
                     freetype \
                     libx11 \
                     ttf-dejavu \
                     libxrender
 
 COPY --from=wkhtmltopdf /bin/wkhtmltopdf /usr/bin/wkhtmltopdf

On Alpine Linux 3.14.2 you don’t need the wkhtmltopdf-binary gem because it can be installed natively. I added the gem to the development group because I only need it on Mac OS X:

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
  gem 'wkhtmltopdf-binary', '~> 0.12.6.5'
end

On Alpine Linux 3.14.2 the wkhtmltopd can be added like this natively:

apk add wkhtmltopdf;

With that it’s globally available.

Anyone experiencing this issue with latest?

GEMFILE gem 'wkhtmltopdf-binary', '~> 0.12.5'

INSTALL gem install wkhtmltopdf-binary

I can confirm this as of today.

I was using the gem for production environment in a ruby:2.5.3-alpine Docker image and it would not work.

Left the gem for development and installed wkhtmltopdf in the image and now it’s working.

If using gem wicked_pdf we need to specify the exe_path where wkhtmltopdf is now installed.

That’s very bad news 😦 In the Alpine release notes they recommend to use weasyprint, an alternative to wkhtmltopdf. Does anybody has experience with it?

Thanks for the suggestion, I will try it now. The package wkhtmltopdf was remove from Alpine starting from the version 3.15.

That’s very bad news 😦 In the Alpine release notes they recommend to use weasyprint, an alternative to wkhtmltopdf. Does anybody has experience with it?

Hi There, since Alpine 3.15 this library has now been removed from their package repository. Having this project now support alpine is more important than ever, since a lot of applications now run in alpine docker containers. Thank you!

@unixmonkey Maybe we can close this issue 🤝 The other gems/repos are good alternatives, as mentioned by guys🥇

Assuming your gems are located in /bundle, you could add after bundle install:

RUN apk add wkhtmltopdf
RUN cd /bundle/ruby/*/gems/wkhtmltopdf-binary-*/bin && ln -s /usr/bin/wkhtmltopdf wkhtmltopdf_"$(. /etc/os-release 2> /dev/null && echo ${ID}_${VERSION_ID})"_amd64

It’s ugly but works like a charm

yes, it was available in the console. I could type wkhtmltopdf and to the help instructions.

Just installing the wkhtmltopdf did not help me. I followed this instructions and it helped me: https://stackoverflow.com/a/56971343/847670