带有Wkhtmltopdf的Pdfkit在Mac上挂起

时间:2018-03-31 10:54:58

标签: ruby-on-rails ruby wkhtmltopdf pdfkit

我正在尝试在Mac上使用带有cell.productImage.downloadImg(from: (arrayImg?[indexPath.row].url)!) 的PDFkit,但不幸的是,它被卡住或挂起并继续加载。

当从终端contentType: false processData: false

手动运行时,这会成功生成pdf

我已尝试过StackOverflow上可用的所有可能解决方案,我不确定如何调试此问题。

我在Ubuntu上使用wkhtmltopdf和pdfkit gem成功生成报告但遗憾的是,我无法使用pdfkit在Mac上生成pdf。

建议,请

wkhtmltopdf http://google.com google.pdf

初始化程序中的PDFkit配置

wkhtmltopdf

在Application.rb

⇒  ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin17.0]

⇒  which ruby
/Users/mac/.rvm/rubies/ruby-2.1.1/bin/ruby

⇒  which wkhtmltopdf
/usr/local/bin/wkhtmltopdf

⇒  wkhtmltopdf --version
wkhtmltopdf 0.12.4 (with patched qt)

⇒  brew config

HOMEBREW_VERSION: 1.5.13
ORIGIN: https://github.com/Homebrew/brew
HEAD: 0f4e22e28d3b65a6c8dbb0f270bb6d262a2429d6
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: dc57a79d6c422c2052df8b33a1782a43cc1cfd53
Core tap last commit: 7 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_AWS_ACCESS_KEY_ID: set
HOMEBREW_AWS_SECRET_ACCESS_KEY: set
CPU: quad-core 64-bit haswell
Homebrew Ruby: 2.3.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/bin/ruby
GCC-4.2: build 5666
Clang: 9.0 build 900
Git: 2.11.0 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Perl: /usr/local/bin/perl => /usr/local/Cellar/perl/5.24.0_1/bin/perl
Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /Users/mac/.rvm/rubies/ruby-2.1.1/bin/ruby
Java: N/A
macOS: 10.13.1-x86_64
Xcode: 9.2
CLT: 9.2.0.0.1.1510905681
X11: N/A

谢谢

2 个答案:

答案 0 :(得分:1)

在MacOS上为我工作正常。您能否发布以下内容:

ruby -v
which ruby
which wkhtmltopdf
wkhtmltopdf --version

希望您使用自制软件,如果是这样输出

brew config

让我们看看这里发生了什么。

确保没有卡住的流程

ps aux | grep wkhtmltopdf

试试这个

PDFKit.configure do |config|
  config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
  config.default_options = {
    :encoding      => "UTF-8",
    :page_size     => 'Letter',
    :zoom          => 0.75,
    :margin_top    => '0.5in',
    :margin_right  => '0.5in',
    :margin_bottom => '0.7in',
    :margin_left   => '0.5in',
    :load_error_handling => 'ignore'
  }
end

请参阅https://github.com/pdfkit/pdfkit#configuration

# in application.rb(Rails3+) or environment.rb(Rails2)
require 'pdfkit'
config.middleware.use PDFKit::Middleware

同样在开发中,您可能需要运行多线程服务器,即独角兽

https://github.com/pdfkit/pdfkit#troubleshooting

答案 1 :(得分:0)

我的不好就是把它发布给像我这样的其他菜鸟 - 在制作时我使用的是Unicorn,但在本地我试图用Webrick运行它,webrick在它有2个请求的时候卡住了,而独角兽处理它。