Search code examples
ruby-on-railsrubywkhtmltopdfpdfkit

Pdfkit with Wkhtmltopdf hang on Mac


I am trying to use PDFkit with wkhtmltopdf on mac but unfortunately, it is stuck or get hang and kept loading.

This successfully generates the pdf when ran manually from terminal wkhtmltopdf http://google.com google.pdf

I have tried all the possible solutions available on StackOverflow and I am not sure how I debug this issue.

I am successfully generating reports using wkhtmltopdf and pdfkit gem on Ubuntu but unfortunately, I am unable to generate pdf on Mac using pdfkit.

Suggestions, please

⇒  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 Configurations in the initializer

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

In Application.rb

require 'pdfkit'
config.middleware.use PDFKit::Middleware, :print_media_type => true

Thank you


Solution

  • My bad just posting it for some other noob like me -- on production I was using Unicorn but locally i was trying to run it with Webrick and webrick get stuck when it has 2 requests at once while unicorn handle it.