Why does PDFKit/wkhtmltopdf hang but renders PDF as expected when Rails app is killed?

后端 未结 7 1447
無奈伤痛
無奈伤痛 2020-12-04 12:18

Background

After reading around it seemed to me that Prawn is out and wkhtmltopdf is in. It also seems like the PDFKit and wicked_pdf gems for Rails are the new co

相关标签:
7条回答
  • 2020-12-04 12:51

    Mine was also hanging and opening the wkhtmltopdf icon in the dock.

    I actually found the problem for me was I only had 1 unicorn worker process running. Once I added more than 1 it worked fine.

    I'm running wkhtmltopdf 0.9.9 on OS X with pdfkit 0.6.2

    0 讨论(0)
  • 2020-12-04 12:52

    Try the last version. The easy way install on MacOS:

    brew install Caskroom/cask/wkhtmltopdf
    
    0 讨论(0)
  • 2020-12-04 13:00

    The problem is with wkhtmltopdf itself, specifically, any version after 0.9.9. wkhtmltopdf hangs when run directly from the command-line.

    Steps to correct:

    brew uninstall wkhtmltopdf
    cd /usr/local/Library/Formula/
    git checkout 6e2d550 /usr/local/Library/Formula/wkhtmltopdf.rb
    brew install wkhtmltopdf
    

    Then verify the correct version is installed wkhtmltopdf --version which should yield wkhtmltopdf 0.9.9

    Citations:

    1. https://github.com/mileszs/wicked_pdf/issues/110
    2. http://wearepandr.com/blog/article/homebrew-and-installing-old-package-versions#blog_nav
    0 讨论(0)
  • 2020-12-04 13:05

    Exact same symptoms but using WickedPdf currently. At this point, I believe the issue lies with wkhtmltopdf as well.

    Unfortunately, neither of the recommendations I've been able to find in Stack/Google worked for me. Instead, I needed to combine several suggestions, including some found in this post.

    Solution was:

    1. brew uninstall wkhtmltopdf
    2. find and delete any copies of wkhtmltopdf in /usr/bin
    3. comment WickedPdf.config line in config/initializers
    4. add config.threadsafe! to development.rb
    5. remove middleware and allow 'show' action of main controller to handle pdf requests (may not be necessary)
    6. add wkhtmltopdf-binary to gemfile
    7. bundle
    8. restart server
    9. You may also need to add Mime::Type.register_alias "application/pdf", :pdf to config/initializers/mime_types.rb (for me, this causes 'warning: already initialized constant PDF')

    My set-up was: Mac OSX Mountain Lion with Rails 3.2.1, Webrick, Postgres and wkhtmltopdf-binary (0.9.9.1).

    0 讨论(0)
  • 2020-12-04 13:06

    Try editing config/initializer/pdfkit.rb in the following way:

    PDFKit.configure do |config|
    
    config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
    
    config.default_options = {
    
      :encoding=>"UTF-8",
      :page_size=>"A4",
      :margin_top=>"0.25in",
      :margin_right=>"0.1in",
      :margin_bottom=>"0.25in",
      :margin_left=>"0.1in",
      :disable_smart_shrinking=> false
    }
    end
    
    0 讨论(0)
  • 2020-12-04 13:10

    I got the same issue. It works when I added: 'config.threadsafe!' in application.rb as the answer in the stack. Hope this help.

    0 讨论(0)
提交回复
热议问题