wkhtmltopdf error when generating pdf with lots of pages with header / footer

1,043 views
Skip to first unread message

Matthew Meyer

unread,
Aug 21, 2014, 5:38:23 PM8/21/14
to wkhtmltop...@googlegroups.com
Hi all, 

I've posted a question regarding an issue I am having using wkhtmltopdf (via rubys pdfkit gem) over on stackoverflow but it hasn't gotten much traction. Trying to post here as well:


I am using pdfkit (which uses wkhtmltopdf under the hood) to generate PDFs in my rails app. Following the guide here i've gotten it mostly working for basic cases of PDFs. I am now running into an issue when attempting to generate a PDF with lots of pages thats also has headers/footers. The error I see from wkhtmltopdf in console when attempting to generate the PDF is:

QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files
QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe

A minimal example of the html which can be used to recreate the error:

<!-- content of pdf_header_url is the character "h" -->
<meta content="<%= pdf_header_url %>" name="pdfkit-header-html"/>
<!-- content of pdf_footer_url is the character "f" -->
<meta content="<%= pdf_footer_url %>" name="pdfkit-footer_html"/>
<% [*1..3].each do |j|%>
  <h1><%= j %></h1>
  <ul>
    <% [*1..1000].each do |i|%>
      <li><%= i %></li>
    <% end %>
  </ul>
<% end %>

Note that removing the of headers/footers tags allows the pdf to render fine.

The actual ruby code to generate the PDF is:

def view_report
    html = render_to_string(:template => 'pdf/pdf_body.html', :layout => false)
    kit = PDFKit.new(html)
    pdf = kit.to_pdf
    send_data pdf, :type => 'application/pdf', :disposition => 'inline', :filename => 'foo.pdf'
  end

Visiting this controllers route will generate the PDF. And then lastly, I also have a controller for the header/footer, since those "partials" need to be fetchable via url:

class PdfController < ApplicationController

  def header
    render :layout => false
  end

  def footer
    render :layout => false
  end

end

The values of pdf_header_url and pdf_footer_url are literally just "h" and "f" for the sake of a minimal reproducible example.

Does anyone familiar with wkhtmltopdf have any recommendations on furthur debug steps to take to get around this issue?


Reply all
Reply to author
Forward
0 new messages