title: wkhtmltopdf falis for 1000+ pages ruby on rails
body: <p>Generating a pdf of 1000+ pages fails in case of header supplied.
  layouts/header is a header.pdf.haml file.
  After going through various suggestions, increased the open files limit on ubuntu also didn't work.</p>
  
  <pre><code>respond_to do |format|
    format.html
    format.xlsx
    format.pdf { render pdf: "Test report", dispoistion: :attachment,
        :show_as_html =&gt; (params[:d].present? &amp;&amp; params[:d] == "true"),
        layout: "pdf.html.haml",
        margin: {
          top: 38
        },
        header: {
          spacing: 2,
          html: {
            template: 'layouts/header',
            formats:  [:pdf],
            handlers: [:haml],
            layout: nil,
            locals: {
              title: "Test Report"
            }
          }
      }
    }
  end
  </code></pre>
  
  <blockquote>
    <p>RuntimeError (Failed to execute:
    ["/shared/bundle/ruby/2.2.0/bin/wkhtmltopdf", "-q", "--page-size",
    "Letter", "--margin-top", "38", "--header-spacing", "2",
    "--header-html",
    "file:////tmp/wicked_header_pdf20180828-94225-2oante.html",
    "--footer-left", "Test Online", "--footer-right", "Page [page] of
    [topage]", "file:////tmp/wicked_pdf20180828-94225-f0g5x0.html",
    "/tmp/wicked_pdf_generated_file20180828-94225-80q49r.pdf"] Error: PDF
    could not be generated! PaintDevice: Cannot destroy paint device that
    is being painted ):</p>
  </blockquote>
  
  <p>Added, could anyone suggest a way how to make header point to local path.
  As suggested in <a href="https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2093#issuecomment-167955213" rel="nofollow noreferrer">https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2093#issuecomment-167955213</a></p>