0

I am trying to generate pdf in production server.In local host everything works fine for me. No error while I am generating PDF. but in production getting this error.

    2.3.1 :001 > WickedPdf.new.pdf_from_string("<p>hello</p>")
RuntimeError: Failed to execute:
["/home/ubuntu/.rvm/gems/ruby-2.3.1/bin/wkhtmltopdf", "file:////tmp/wicked_pdf20211210-26525-1jrpwxd.html", "/tmp/wicked_pdf_generated_file20211210-26525-1nj8sms.pdf"]
Error: PDF could not be generated!
 Command Error: /home/ubuntu/.rvm/gems/ruby-2.3.1/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf:61:in `<top (required)>': Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 CentOS 6/7/8, Debian 9/10, archlinux amd64, or intel-based Cocoa macOS (missing binary: /home/ubuntu/.rvm/gems/ruby-2.3.1/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf_ubuntu_14.04_amd64). (RuntimeError)
    from /home/ubuntu/.rvm/gems/ruby-2.3.1/bin/wkhtmltopdf:25:in `load'
    

Gemfile that I have used

gem 'wicked_pdf', '~> 2.1'
gem 'wkhtmltopdf-binary', '~> 0.12.6.5'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.6.0'

config/initializers/wicked_pdf.rb file

if Rails.env.production?
  wkhtmltopdf_path = "/home/ubuntu/.rvm/gems/ruby-2.3.1/bin/wkhtmltopdf"
else
  # Linux (check your processor for Intel x86 or AMD x64)
  # wkhtmltopdf_path = "#{Rails.root}/bin/wkhtmltopdf-amd64"
  # wkhtmltopdf_path = "#{Rails.root}/bin/wkhtmltopdf-i386"
  # OS X
  wkhtmltopdf_path = "#{Rails.root}/bin/wkhtmltopdf-0.9.9-OS-X.i386"
  # Windows
  # wkhtmltopdf_path = 'C:\Program Files/wkhtmltopdf/wkhtmltopdf.exe'
end
WickedPdf.config = { exe_path: wkhtmltopdf_path, wkhtmltopdf: wkhtmltopdf_path }

Using ruby version 2.3.1 Rails 4.2.7.1 Bundler version 2.2.30

SreRoR
  • 1,151
  • 1
  • 17
  • 44
  • This is what the error says: `Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 CentOS 6/7/8, Debian 9/10, archlinux amd64, or intel-based Cocoa macOS`. What kind of server is your production? – razvans Dec 10 '21 at 07:48
  • Ubuntu 14.04 version – SreRoR Dec 10 '21 at 08:24
  • That answers your issue :). It requires 16.04/18.04/20.04. – razvans Dec 10 '21 at 08:25
  • Check this. https://stackoverflow.com/questions/17557064/wicked-pdf-does-not-run-on-ubuntu-server-wkhtmltopdf-cannot-connect-to-x-serv. It seems there's a way to run it on ubuntu 14. – razvans Dec 10 '21 at 08:29
  • tried installing packages for 14.04 amd64, still error `wkhtmltopdf http://www.google.com google.pdf /home/ubuntu/.rvm/gems/ruby-2.3.1/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf:61:in `': Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 CentOS 6/7/8, Debian 9/10, archlinux amd64, or intel-based Cocoa macOS (missing binary: /home/ubuntu/.rvm/gems/ruby-2.3.1/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf_ubuntu_14.04_amd64). (RuntimeError)` – SreRoR Dec 10 '21 at 09:08
  • @SreRoR You could downgrade to an older version of the `wkhtmltopdf` binary (either the gem, or installed another way). The version of the gem you are using only packages binaries for certain platforms, and yours is not supported. Older versions may work. – Unixmonkey Feb 04 '22 at 18:49

0 Answers0