I use pdfkit (which uses wkhtmltopdf under the hood) to create PDF files in my rails application. Following the guide here , I got it mainly for basic cases of PDF files. I am now having a problem when trying to create a PDF file with a large number of pages that also have headers and footers. The error that I see from wkhtmltopdf in the console when trying to generate a PDF:
QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe
The minimum html example that can be used to recreate the error:
<meta content="<%= pdf_header_url %>" name="pdfkit-header-html"/> <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 %>
Please note that removing header / footer tags allows the PDF file to render perfectly.
Actual ruby ββcode for creating a PDF file:
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
A visit to this route of controllers will lead to the creation of a PDF file. And finally, I also have a controller for the header / footer, since these "partial" ones must be selected via the URL:
class PdfController < ApplicationController def header render :layout => false end def footer render :layout => false end end
The values ββpdf_header_url and pdf_footer_url are literally the letters "h" and "f" for a minimal reproducible example.
Anyone familiar with wkhtmltopdf have any recommendations regarding the furthur debugging steps to solve this problem?
source share