我正在使用pdfkit(在引擎盖下使用wkhtmltopdf)在我的rails应用程序中生成PDF.按照指南
here,我得到它主要用于PDF的基本情况.在尝试生成包含大量页面的PDF时,我现在遇到了一个问题,这些页面也有页眉/页脚.尝试生成PDF时,我在控制台中从wkhtmltopdf看到的错误是:
QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe
<!-- 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 %>
请注意,删除页眉/页脚标记允许pdf呈现正常.@H_403_5@
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
访问此控制器路由将生成PDF.最后,我还有一个页眉/页脚控制器,因为那些“部分”需要通过url获取:@H_403_5@
class PdfController < ApplicationController def header render :layout => false end def footer render :layout => false end end
pdf_header_url和pdf_footer_url的值实际上只是“h”和“f”,以获得最小的可再现示例.@H_403_5@