Inserting a page break in HTML without the p element to avoid blank pages in PDF

Viewed 141

I am using Grover to convert HTML pages to PDF, which leverages Puppeteer for Google Chrome. I have a bunch of Ruby on Rails partials that I am cycling through and rendering, and I am inserting a page break between each partial render. However, I noticed that my page break is a p element, and sometimes if the text on the page extends all the way to the bottom of the page by the footer, then the p element ends up being on the next page, followed by the page break. This causes a blank page.

Here's what I'm using as a page break:

<p style="page-break-after: always;">&nbsp;</p>

I think this is what's happening:

enter image description here

If I adjust the footer margins to be smaller, then it works fine (because the p element has more room on the existing page), but I constantly have to tweak this footer margin.

This is what my Rails code looks like:

    <% items.each do |item| %>
        <% unless item == items[0] %>
            <p style="page-break-after: always;">&nbsp;</p>
        <% end %>
        <%= render partial: "common/report_templates/shared/item" %>
    <% end %>
0 Answers
Related