1

I use table in pdf but when new page starting at that time row is cut half In upper page and half in next page.
I use html-pdf for creating pdf.
I also try page break css property but no any change in my output.

used ejs

chirag sorathiya
  • 1,223
  • 8
  • 29

2 Answers2

2

i resolved that add small CSS

page-break-inside

and it's working table row is not cutting on ending of first page and starting of second page of first ans second page.

chirag sorathiya
  • 1,223
  • 8
  • 29
  • I am facing the same issue can you please look into [this](https://stackoverflow.com/questions/61018815/page-break-not-working-in-html-pdf-coverter-in-nodejs) – Anuj Kumar Pal Apr 04 '20 at 09:44
1

Adding page-break-inside alone may not solve the problem when the table is long. I solved a similar problem by turning a table into multiple mini tables with the command not to break them.

Example CSS:

table, tr, td { page-break-inside: avoid; }

Example HTML:

<table>
    <tr>
        <th>Title A</th>
        <th>Title B</th>
        <th>Title C</th>
    </tr>
</table>
<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
</table>
<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
</table>
<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
</table>
...

Well, this is not the best programming practice, however this is a very reported error and I have not found any other solution for this problem that the html-pdf lib generates on node.