Open Manidavid opened 4 years ago
I suspect you are running into an issue similar to the one described in this StackOverflow post, or this issue.
Please check those out and see if maybe they apply to you. I might try directly referencing the named binary, and not the wkhtmltopdf-binary binstub, since that stub invokes Ruby, and it may not run with the same user and permissions that the rest of your app runs as.
Let me know how it goes and what you find out!
@unixmonkey, I followed the steps posted on issue https://github.com/mileszs/wicked_pdf/issues/890 and uncompressed the binary from the GEM bin path(vendor/bundle/ruby/2.6.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/) and pointed to exe path.
gunzip wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_16.04_amd64.gz
config/initializers/wicked_pdf.rb
WickedPdf.config = {
# Path to the wkhtmltopdf executable: This usually isn't needed if using
# one of the wkhtmltopdf-binary family of gems.
# exe_path: '/usr/local/bin/wkhtmltopdf',
# or
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
exe_path: Rails.root.join('/data/apps/project-path/vendor/bundle/ruby/2.6.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_16.04_amd64')
# Layout file to be used for all PDFs
# (but can be overridden in `render :pdf` calls)
# layout: 'pdf.html',
}
Here getting the RuntimeError on executing the path
RuntimeError (Failed to execute:
[#<Pathname:/data/apps/project-path/vendor/bundle/ruby/2.6.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_16.04_amd64>, "file:////tmp/wicked_pdf20200322-6255-14q4v9h.html", "/tmp/wicked_pdf_generated_file20200322-6255-1y2l8gy.pdf"]
Error: no implicit conversion of Pathname into String):
F, [2020-03-22T12:33:05.570275 #6255] FATAL -- : [5c7815dc-0558-45c2-ac0a-b95e99ce2992]
Also i tried the another stackoverflow post which you mentioned above by changing the exec path to exe_path: '/usr/bin/wkhtmltopdf still not helping to resolve the issues.
Tempfile.new
doesn't take a Pathname
object, you'll need to convert to a string with to_s
, like this:
Rails.root.join('/data/apps/project-path/vendor/bundle/ruby/2.6.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_16.04_amd64').to_s
Now its finally working as expected. so every time do i need to do the same setups on production, still not sure why the ruby wrapper was causing this error though.
Thanks for helping out.
@Manidavid If your Rails app runs as a user with a Ruby that is only available to it, when it shells out to run wkhtmltopdf
, in some configurations that might be a different Ruby, or it might not have one at all.
Also, I notice you are using the Ubutntu version. If production is also Ubuntu, there's nothing you need to change, but if it's something else, you may need to pick out a different binary.
My suggestion to you would be to vendor the specific wkhtmltopdf
versions you need in your app for both dev and production, or setup your deploy process to specifically copy that file to somewhere it can execute it easily.
Then point my initializer at those files
WickedPdf.config = {
exe_path: Rails.root.join(
'bin',
(Rails.env.development? ? 'wkhtmltopdf-ubuntu' : 'wkhtmltopdf-centos')
).to_s
}
Once those files are vendored, you can also remove the wkhtmltopdf-binary
gem, which is quite large, since it includes many different versions of the binary for different architectures.
Am using wicked_pdf gem and it works fine in my local development and production envs, but i deployed it to aws ec2 instance(Ubuntu) and trying to generate the pdf in production it doesn't works.
This is my setup:
Gemfile
versions
config/initializers/wicked_pdf.rb
controller/users_controller.rb
I Already have html view in /views/users/show.html.erb.
Production error logs