Baxter Baxter - 9 months ago 27
HTML Question

How do I prevent a blank last page?

I am iterating over a list of objects. With each iteration I build and populate a table which contains the content of a single page.

I am using CSS to add a page break after each table.

table { page-break-after: always; }

This works great, except that I am always getting a blank last page. Which I assume is due to the last table iteration applying a page break.

I have tried.

table { page-break-after: always; }
table { page-break-after: auto; }
table { page-break-after: left; }
table { page-break-after: right; }

However, I always get that blank last page.

Is there another method of inserting page breaks that would not create the blank last page?

Or maybe some way to detect if is the last iteration and not insert the last page break?


You could add this:

table:last-of-type {
    page-break-after: auto

Or maybe

body > *:last-child {
    page-break-after: auto