Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 493
Baxter Avatar asked Apr 25 '12 14:04

Baxter


2 Answers

You could add this:

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

Or maybe

body > *:last-child {
    page-break-after: auto
}
like image 189
pbfy0 Avatar answered Oct 06 '22 01:10

pbfy0


I'm using ruby to create pages. I created different css to breaking and no breaking.

#publication_no_break{
/* stuff here */
page-break-after: avoid;
}

#publication_break{
/* stuff here */
page-break-after: always;
}

And on code I count every page I need to print and

<% if page != total_pages %>
< .... .... id="publication_break" >
<% else %>
< .......... id="publication_no_break">
<% end %>

You can try something like this in any language you're coding.

like image 45
Pedro Ivan Avatar answered Oct 06 '22 01:10

Pedro Ivan