The wkhtmltopdf binary is available for Alpine 3. 9+, but I get either a blank PDF or the error “Could not load the document” - despite the fact that everything works fine on MacOSX. Turns out you need to explicitly enable fonts for alpine builds (at least)
Controller action
def show respond_to do |format| format.html do render 'pdfs/templates/my_template.html.erb' end format.pdf do render( pdf: "file_name", template: 'pdfs/templates/my_template.html.erb', disposition: 'inline' ) end end end
The above worked locally on a MacOSX computer, but the document failed to load the document on the ruby alpine image server as shown below
Dockerfile
FROM ruby:2.6.3-alpine3.10 ....
even simpler example failed with empty pdf
respond_to do |format| format.pdf do pdf = WickedPdf.new.pdf_from_string('TESTING 123') send_data( pdf, filename: "file_name.pdf", type: 'application/pdf', disposition: 'inline' ) end end
Decision
Dockerfile
FROM ruby:2.6.3-alpine3.10 ....
Ideally, Alpine should include the base font with the wkhtmltopdf
package, but until then I found it to be a useful source of information and / or a good way to add a multi-stage Docker file.
https://github.com/madnight/docker-alpine-wkhtmltopdf/blob/master/Dockerfile
Note:
The lack of an explicit font package in alpine can also lead to a failure of the PDF conversion using libreoffice
. We found corrupted PDF files, in particular, when converting from docx files.
Joel Sugarman
source share