带有 Wkhtmltopdf 的 PDFkit 挂在 Mac
Pdfkit with Wkhtmltopdf hang on Mac
我正在尝试在 mac 上将 PDFkit 与 wkhtmltopdf
一起使用,但不幸的是,它卡住了或挂起并一直在加载。
当 运行 从终端 wkhtmltopdf http://google.com google.pdf
手动生成 pdf 时
我已经尝试了 Whosebug 上可用的所有可能解决方案,但我不确定如何调试此问题。
我在 Ubuntu 上使用 wkhtmltopdf
和 pdfkit gem 成功生成了报告,但不幸的是,我无法在 Mac 上使用 pdfkit 生成 pdf。
请多多指教
⇒ 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
初始化程序中的 PDFkit 配置
PDFKit.configure do |config|
config.default_options = {
:encoding => "UTF-8",
#:page_width => '14mm',
#:page_height => '14mm',
: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
在Application.rb
require 'pdfkit'
config.middleware.use PDFKit::Middleware, :print_media_type => true
谢谢
我在 MacOS 上运行良好。你能请 post 以下输出:
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
还在开发中,您可能需要 运行 一个 multi-threaded 服务器,即 unicorn
我的错误只是将它发布给像我这样的其他菜鸟——在生产中我使用的是 Unicorn 但在本地我试图 运行 它与 Webrick 和 webrick 在一次有 2 个请求时卡住了独角兽处理它。
我正在尝试在 mac 上将 PDFkit 与 wkhtmltopdf
一起使用,但不幸的是,它卡住了或挂起并一直在加载。
当 运行 从终端 wkhtmltopdf http://google.com google.pdf
我已经尝试了 Whosebug 上可用的所有可能解决方案,但我不确定如何调试此问题。
我在 Ubuntu 上使用 wkhtmltopdf
和 pdfkit gem 成功生成了报告,但不幸的是,我无法在 Mac 上使用 pdfkit 生成 pdf。
请多多指教
⇒ 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
初始化程序中的 PDFkit 配置
PDFKit.configure do |config|
config.default_options = {
:encoding => "UTF-8",
#:page_width => '14mm',
#:page_height => '14mm',
: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
在Application.rb
require 'pdfkit'
config.middleware.use PDFKit::Middleware, :print_media_type => true
谢谢
我在 MacOS 上运行良好。你能请 post 以下输出:
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
还在开发中,您可能需要 运行 一个 multi-threaded 服务器,即 unicorn
我的错误只是将它发布给像我这样的其他菜鸟——在生产中我使用的是 Unicorn 但在本地我试图 运行 它与 Webrick 和 webrick 在一次有 2 个请求时卡住了独角兽处理它。