How do I prevent a blank last page?

寵の児 提交于 2019-12-22 07:36:10

问题


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?


回答1:


You could add this:

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

Or maybe

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



回答2:


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.



来源:https://stackoverflow.com/questions/10317705/how-do-i-prevent-a-blank-last-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!