【问题标题】:Im getting 'Error: PDF could not be generated! Bad CPU type in executable' on my m1 macbook我收到'错误:无法生成 PDF!我的 m1 macbook 上的可执行文件中的 CPU 类型错误
【发布时间】:2021-11-29 12:37:10
【问题描述】:

我有 wicked_pdf 和 wkhtmltopdf-binary 的测试。两个 gem 都已安装,但错误不会消失 :( 我尝试使用 Rosetta 安装 gem,但没有任何帮助

错误在这里

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>'

【问题讨论】:

  • @Vishal exe_path: '/Users/larkin/.rvm/gems/ruby-2.7.2/bin/wkhtmltopdf',是的(
  • 你有苹果m1芯片吗?我的 macbook 也有同样的问题

标签: ruby-on-rails ruby apple-m1


【解决方案1】:

我在带有苹果 m1 芯片的 macbook 上遇到了同样的问题。 为了解决这个问题,您需要手动下载 arm 芯片的二进制文件,最新版本 (0.12.6) 只需转到:https://github.com/wkhtmltopdf/packaging/releases/0.12.6-1 并下载:wkhtmltox-0.12.6-1.macos-cocoa.pkg

然后安装脚本并编辑您的wicked_pdf.rb 文件以指向新安装的二进制文件:

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

您还可以做一些更改以保持其他机器上的先前行为,并仅在已安装时使用非 gem 二进制文件:

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,
}

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 2021-07-06
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多