rposborne/wkhtmltopdf-heroku

libXrender.so.1: No such file or directory

guillaumewrobel opened this issue Β· 15 comments

Since this morning I get this weird error, working with wicked_pdf on a Ruby on Rails app, hosted on Heroku.

Command Error: /app/vendor/bundle/ruby/2.5.0/gems/wkhtmltopdf-heroku-2.12.4.0/bin/wkhtmltopdf-linux-amd64: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory

Doesn't work with Heroku stack v18, had to revert to v16.

I resolved it with:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
and add into project file Aptfile

libfontconfig1
libxrender1

@tonic20 please how do I add to project Aptfile on Heroku? My development environment is Mac, and there’s no Aptfile in my rails project.

Thanks for your awesome work on this build pack.

Hey @mayordwells, you need just add this file into your rails project with content I posted above

@tonic20 Thanks for the suggestion.
But that didn't fix my problem:

Here's my Heroku Log

2018-06-12T11:28:26.965243+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]     5:     %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}
2018-06-12T11:28:26.965244+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]     6:     = wicked_pdf_stylesheet_link_tag 'application', media: 'all'
2018-06-12T11:28:26.965246+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]     7:     = stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", integrity: "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin: "anonymous"
2018-06-12T11:28:26.965248+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]     8:     -# = wicked_pdf_javascript_include_tag 'application'
2018-06-12T11:28:26.965353+00:00 app[web.1]: F, [2018-06-12T11:28:26.965304 #4] FATAL -- : [db3b89d6-d4aa-408c-bed7-21f7eef6e48a] app/views/layouts/pdf_layout.html.haml:6:in `_app_views_layouts_pdf_layout_html_haml___2358158485619679043_69834769302700'
2018-06-12T11:28:26.965354+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a] app/controllers/reports_controller.rb:45:in `block (2 levels) in generate_doc'
2018-06-12T11:28:26.965249+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]     9:     -# = wicked_pdf_javascript_include_tag 'reports'
2018-06-12T11:28:26.965285+00:00 app[web.1]: F, [2018-06-12T11:28:26.965230 #4] FATAL -- : [db3b89d6-d4aa-408c-bed7-21f7eef6e48a]   
2018-06-12T11:28:26.965356+00:00 app[web.1]: [db3b89d6-d4aa-408c-bed7-21f7eef6e48a] app/controllers/reports_controller.rb:43:in `generate_doc'
2018-06-12T11:28:26.969642+00:00 heroku[router]: at=info method=GET path="/tasks/1/reports/1/generate_doc" host=ndt-nordvest.herokuapp.com request_id=db3b89d6-d4aa-408c-bed7-21f7eef6e48a fwd="173.199.120.251" dyno=web.1 connect=1ms service=101ms status=500 bytes=1827 protocol=http

Also here is my template.

!!!
%html
  %head
    %meta{:charset => "utf-8"}
    %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}
    = wicked_pdf_stylesheet_link_tag 'application', media: 'all'
    = stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", integrity: "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin: "anonymous"
    = wicked_pdf_stylesheet_link_tag 'reports'
    / Google Font: Source Sans Pro
    = stylesheet_link_tag "https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700"


  %body
    = yield

And then here's the action for rendering the pdf

def generate_doc
    respond_to do |format|
      format.pdf do  
        render template: 'reports/generate_doc', 
               pdf: 'Test Method Report-' + Time.now.strftime('%v %H:%M:%S').to_s, 
              #  viewport_size: '1280x1024',
               javascript_delay: 1000,
               layout: 'pdf_layout.html.haml', 
               disposition: 'inline'
      end
    end
  end

I have added the Aptfile to the root of my rails app as suggested and added the following:

libfontconfig1
libxrender1

Also have this gem in my gemfile. -

gem 'wicked_pdf' 
gem 'wkhtmltopdf-binary'
gem 'wkhtmltopdf-heroku'

But I'm still getting that error in production, but pdf is being generated in development mode.

Do happen to have a further suggestion for a fix?

Thanks.

@mayordwells did you add the buildpack?

You can confirm by running heroku buildpacks in the project root.

@rposborne Yes I think I do. This is what heroku buildpacks say

ndt-nordvest (master) $ heroku buildpacks
=== ndt-nordvest Buildpack URLs
1. https://github.com/heroku/heroku-buildpack-apt
2. https://github.com/heroku/heroku-buildpack-activestorage-preview
3. heroku/ruby

@mayordwells I don't think your error related to subject "libXrender.so.1: No such file or directory".
Basically buildpack and this Aptfile solve issue which prevent you to deploy wkhtmltopdf binaries on Heroku stack v18.

Adding an Aptfile/buildpack worked for me, thanks for this!

for those who're still having problem, you might not need to add custom buildpack and aptfile anymore, they have just added the library libxrender.so to the Heroku-18 runtime today. πŸŽ‰

https://devcenter.heroku.com/articles/stack-packages
libxrender

This is great news, but I am getting this error now:
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

Any insight on how to fix this?

Thanks!

@benoitongit I haven't tested this but you could probably try heroku buildpacks:add --index 1 heroku-community/apt and add libpng12 to Aptfile?

Let me know if that works

heroku haslibpng16-16 on runtime which supposed to be utilized unless the build on #39 0.12.5.0 Linux Generic AMD64 is not finding that library

Hey, we have issues rendering PNGs (while JPEG are fine) with the Heroku-18 stack. Any leads? #41 (comment)