Search code examples
rubyrubygemspdf-generationwkhtmltopdfmerb

merb - wkhtmltopdf command failed


when am running command like this its generating pdf document:

$ wkhtmltopdf http://google.com google.pdf
Loading pages (1/5)
Resolving links (2/5)                                              
Counting pages (3/5)                                                      
Printing pages (5/5)                                                      
Done   

But when using inside app by pdfkit gem it showing error

merb : worker (port 4000) ~ command failed: "/usr/local/bin/wkhtmltopdf" "--page-size" "Letter" "--print-media-type" "--margin-right" "0.0in" "--encoding" "UTF-8" "--margin-top" "0.5in" "--margin-bottom" "0.5in" "--margin-left" "0.0in" "--quiet" "-" "-" - (RuntimeError)

what am tried:

setting path

config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf '

installing dependencies

sudo aptitude install openssl build-essential xorg libssl-dev

Environment

  • Ubuntu 12.04 amd64
  • merb application
  • ruby 1.8.7

Solution

  • Problem sovled by changing the server port number

    from

    bundle exec merb -a thin #default port 4000
    

    to

    bundle exec merb -a thin -p 3000
    

    and using the gem "wkhtmltopdf-binary"

    Explanation

    can sometimes find that the single threaded web server we use in development can cause a race condition. the browser is tieing up the one thread available, and begins a new web request to create the pdf files html, which causes a 2nd web request. Since your only web server thread is already in use, you can find this to hang.

    To get around this, either run more threads. OR use another port for internal access, and have be the internal URL