3

I have tests with wicked_pdf and wkhtmltopdf-binary. Both gems are installed, but errors dont go away :( Im tried to install gems with Rosetta, but nothing helps me

error is here

Minitest::UnexpectedError:
       RuntimeError: Failed to execute:
       ["/Users/larkin/.rvm/gems/ruby-2.7.2/bin/wkhtmltopdf", "--lowquality", "--footer-center", "конфіденційно", "--footer-left", "Служба етичного контролю", "--footer-right", "[page] / [topage]", "--footer-font-size", "10", "file:////var/folders/sk/3493jp896vj_spzzn_z2zvkm0000gn/T/wicked_pdf20211129-63903-gn9oc5.html", "/var/folders/sk/3493jp896vj_spzzn_z2zvkm0000gn/T/wicked_pdf_generated_file20211129-63903-urbrlu.pdf"]
       Error: PDF could not be generated!
        Command Error: /Users/larkin/.rvm/gems/ruby-2.7.2/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf:50:in `exec': Bad CPU type in executable - /Users/larkin/.rvm/gems/ruby-2.7.2/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_macos_carbon (Errno::EBADARCH)
        from /Users/larkin/.rvm/gems/ruby-2.7.2/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf:50:in `<top (required)>'
        from /Users/larkin/.rvm/gems/ruby-2.7.2/bin/wkhtmltopdf:23:in `load'
        from /Users/larkin/.rvm/gems/ruby-2.7.2/bin/wkhtmltopdf:23:in `<main>'
        from /Users/larkin/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `eval'
        from /Users/larkin/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `<main>'

2 Answers2

4

The installation/update of Rosetta (on MacOS Monterey 12.2) solved this issue for me with the following command :

softwareupdate --install-rosetta

Maybe it can help others

SLgz
  • 168
  • 1
  • 6
  • 1
    Rosetta helps to run apps which are supported for intel chips on MacOS. Thank you @SLgz for this answer, it worked for me. I figured out the problem when I saw this error: bad CPU type in executable: wkhtmltopdf – hithard Sep 14 '22 at 07:16
  • 1
    it works for M2 as well – new2cpp Jun 06 '23 at 07:54
2

I had the same issue on macbook with apple m1 chip. In order to fix that, you need to manually download binary for arm chip, for newest release (0.12.6) just go to: https://github.com/wkhtmltopdf/packaging/releases/0.12.6-1 and download: wkhtmltox-0.12.6-1.macos-cocoa.pkg

Then install script and edit your wicked_pdf.rb file to point to newly installed binary:

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf',
}

You can also do some changes to keep previous behavior on other machines, and use non gem binary only when already installed:

if File.exist?('/usr/local/bin/wkhtmltopdf')
  binary_path = '/usr/local/bin/wkhtmltopdf'
else
  binary_path = Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
end

WickedPdf.config = {
  exe_path: binary_path,
}
Paweł Dedio
  • 1,338
  • 12
  • 20