user782104
user782104

Reputation: 13545

How to detect page break for long table when generate PDF

I am using phantomjs (but it should also apply to any pdf generate library e.g. pdfjs etc...) to generate PDF from HTML,

the problem is a long table will split when there is a page-break, how to avoid that e.g. detect when the height is exceed the A4 size , close the table, and create another table?

Have tried using the CSS but no luck:

.page-break{
    page-break-before:always;
    page-break-inside:avoid;
    margin-top: 300mm; /*phantomjs renders it on the top of the next page*/
}

table { page-break-after:auto }
tr    { page-break-inside:avoid; page-break-after:auto }
td    { page-break-inside:avoid; page-break-after:auto }
thead { display:table-header-group }
tfoot { display:table-footer-group }

And the current HTML code:

<div class="page-break">
    <h3>Heading</h3>
    <table class="table table-bordered text-center" width="100%">
        <tr><td>....</td><td>....</td></tr>...
    </table>
</div>

enter image description here

Upvotes: 4

Views: 3658

Answers (1)

Paladin
Paladin

Reputation: 1637

AFAIK is there no way to "detect" a page break when creating PDF. Just count the height you used so far and calculate the break depending on the page height.

Upvotes: 2

Related Questions