Open Jonattb opened 1 year ago
When your app shells out to call wkhtmltopdf
(or anything else), it's running as a user on that system, and that user might not have the rbenv
environment loaded.
It executes the binstub under vendor/bundle/ruby/3.0.0/bin/wkhtmltopdf
, but that's just a ruby file, which halts its own execution because it's running under a different version of Ruby than it was built for.
There's 2 paths we can take here:
The first (harder path) is to make it so that when your app spawns a new process, that that user's shell automatically loads the 3.0 rbenv
environment, so that when it calls ruby
, it's calling out the correct version.
The second (easier method) is to specify an exact path to the binary by adding it's path via configuration to your project like this: __config/initializers/wicked_pdf.rb__
WickedPdf.config = {
exe_path: '/usr/local/bin/wkhtmltopdf',
enable_local_file_access: true
}
You didn't post that you were using a provider gem for wkhtmltopdf
, but if you were, this might look like:
exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf_linux_amd64"
I'm having this challenge too. I attempted the recommended approach of specifying the exact path to wkhtmltopdf, but I'm still getting the ruby version mismatch error. I'm using the wkhtmltopdf-binary gem version 0.12.6.7. Things worked at some point in my environment, but I'm not sure when it broke, or what caused it to break. I don't know if people have just been ignoring the error and not telling me about it, or if it just recently broke. Any help is greatly appreciated!
My specified ruby version is 3.0.4, and my system version is 2.7.0.
My WickedPdf initializer looks like this.
exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf",
enable_local_file_access: true
}
and the error
["/var/www/rubyapps/my-app/releases/20240729134726/vendor/bundle/ruby/3.0.0/gems/wkhtmltopdf-binary-0.12.6.7/bin/wkhtmltopdf", "--enable-local-file-access", "--orientation", "Landscape", "file:////tmp/wicked_pdf20240729-950697-n6d7kk.html", "/tmp/wicked_pdf_generated_file20240729-950697-e86w3a.pdf"]
Error: PDF could not be generated!
/home/deploy/.rbenv/versions/3.0.4/lib/ruby/3.0.0/bundler/definition.rb:425:in `validate_ruby!': Your Ruby version is 2.7.0, but your Gemfile specified 3.0.4 (Bundler::RubyVersionMismatch)
My WickedPdf initializer looks like this.
exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf", enable_local_file_access: true }
@andyrue I can see here you are just pointing to bin/wkhtmltopdf
, which is the Ruby binstub, which has to load the version of Ruby outside of your app.
The important part of what I said above is pointing to the exact binary needed for your platform, like bin/wkhtmltopdf_linux_amd64
. This will call the linux binary itself, without needing Ruby in that system shell at all.
Thank you, I did try pointing it to the ubuntu_20.04 file, but didn't realize I needed to uncompress it first. Uncompressing it and making it executable has me running again. However, I noticed when I deploy a new version of the app, I have to uncompress it again. Feels like I'm doing something wrong if I need to do that every time. Thank you again for your help.
I have an error with the ruby version. I use rbenv to install ruby and I have two versions, system and 3.0.3. When I do
rbenv shell system
and thenruby -v
I get 2.5.1the error I get is
I don't know why I get 2.5.1 if I use 3.0.3
wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf): 2.7.0
wkhtmltopdf version (output of wkhtmltopdf --version): 0.12.6 (with patched qt)
whtmltopdf provider gem and version if one is used:
platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar): Ubuntu 18.04.6 LTS