PDFKit (wkhtmltopdf) Broken Pipe, OS X and Rails 3

后端 未结 2 1134
清歌不尽
清歌不尽 2020-12-14 20:19

I\'m using PDFKit (which uses wkhtmltopdf) in an attempt to render a view as pdf within a Rails 3 app.

PDFKit renders with Errno::EPIPE (Broken pipe) po

相关标签:
2条回答
  • 2020-12-14 20:41

    Change /lib/pdfkit/pdfkit.rb:35 to the following and everything works as expected (with middleware too).

    args << '--quit'
    
    0 讨论(0)
  • 2020-12-14 20:45

    Regarding changing the quiet argument to quit.

    This change is only valid if you are using the wkhtmltopdf gem which uses a very old version of the wkhtmltopdf binary.

    With the wkhtmltopdf gem

    10:32:15 wkhtml >     wkhtmltopdf --version
    wkhtmltopdf 0.8.3 using wkhtmltopdf patched qt
    Copyright (C) 2008,2009 Jakob Truelsen,
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    Written by Jakob Truelsen
    Patches by Mário Silva and Emmanuel Bouthenot
    
    10:32:16 wkhtml >     wkhtmltopdf --help | grep quit
      -q, --quit                      Be less verbose.
    10:32:16 wkhtml >     wkhtmltopdf --help | grep quite
    10:32:19 wkhtml > 
    

    With the latest binary I have installed

    10:33:40 tmp > wkhtmltopdf --version
    Name:
      wkhtmltopdf 0.9.9
    
    License:
      Copyright (C) 2008,2009 Wkhtmltopdf Authors.
    
    
    
      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
      This is free software: you are free to change and redistribute it. There is NO
      WARRANTY, to the extent permitted by law.
    
    Authors:
      Written by Jakob Truelsen. Patches by Mário Silva, Benoit Garret and Emmanuel
      Bouthenot.
    
    10:33:50 tmp > wkhtmltopdf --help | grep quit
    10:34:02 tmp > wkhtmltopdf --help | grep quiet
      -q, --quiet                         Be less verbose
    10:34:07 tmp > 
    

    The spelling mistake exists in the old binary that comes with the wkhtmltopdf gem. I would suggest you monkey patch pdfkit with an initialize or something based on if you included the wkhtmltopdf gem or not.

    I would also accept a pull request that made pdfkit aware of the version of wkthtmltopdf it was running against and conditionally switched that argument.

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