Google Answers Logo
View Question
 
Q: Printing HTML tables - how to prevent cell splitting? ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: Printing HTML tables - how to prevent cell splitting?
Category: Computers > Programming
Asked by: g8z-ga
List Price: $5.00
Posted: 17 Feb 2003 10:10 PST
Expires: 19 Mar 2003 10:10 PST
Question ID: 162574
Hello,
I have a table in HTML which spans multiple pages when printed. Some
of the table cells print onto separate pages. How can I prevent this?
- Darren

Clarification of Question by g8z-ga on 17 Feb 2003 10:13 PST
I would also like to know if an entire table can be prevented from
splitting... e.g. I have an HTML document that looks something like:

<table>...</table>
<br><br>
<table>...</table>
<br><br>
<table>...</table>

Instead of splitting, if a page break is needed in the middle of a
table, the entire table should be print on the next page.
Answer  
Subject: Re: Printing HTML tables - how to prevent cell splitting?
Answered By: mvguy-ga on 17 Feb 2003 17:20 PST
Rated:5 out of 5 stars
 
I've looked into this some more, and I have some good news and some
bad news.

The good news is that there is a Cascading Style Sheets 2 attribute
that is designed to do exactly what you want it to.  It is the
"page-break-inside" attribute, and if you use the "avoid" type it will
prevent a table from being split when printed.

Here is a page that explains the attribute and gives and example of
how it is used:

PAGE-BREAK-INSIDE attribute
http://big.faceless.org/products/report/docs/tag/atts/page-break-inside.html

This page does a good job of explaining it also:

Breaking Pages
http://www.webreview.com/tag/2000/11_24_00.shtml

Here are some other pages where it is explained, although not as
clearly:

CSS Quick Reference
http://www.tcnj.edu/~nardozza/tables3.html

Printing Tables - Section Stay Together
http://www.faqchest.com/msdn/IE-HTML/script-02/script-0205/script02051508_14617.html

CSS-2 Extensions
http://members.lycos.co.uk/lawnet/CSS2.HTM

That was the good news.  The bad news is that, as the second link
above indicated, very few if any of the page-break attributes are
supported by current browsers.  I tested the page-break-inside
attribute on recent versions of Internet Explorer, Mozilla and Opera,
and none of them supported it.  I suspect, however, that if CSS2 grows
in popularity one of the browsers will soon be able to do what you
want.

I have thought of two workarounds:

1) Put tables on separate web pages.

2) Place tall, skinny graphics (you can make them white if you're
using a white background so it can't be seen) immediately to the left
or the right of the table, or perhaps even in the table.  Most
browsers don't split graphics when printing, so this should work (I
haven't tried it).

I'm sorry I wasn't able to find a good way to do what you want. I hope
this information helps, however.

mvguy




Search strategy:  I did the first search below and saw an article that
referred to the CSS2 attribute, so then I did a search for the
attribute to find out more of what I wanted.

Google search: "printing tables" split
://www.google.com/search?q=%22printing+tables%22+split&sourceid=opera&num=25&ie=utf-8&oe=utf-8

Google search: page-break-inside avoid
://www.google.com/search?num=25&hl=es&ie=UTF-8&oe=utf-8&q=page-break-inside+avoid&btnG=B%C3%BAsqueda+en+Google
g8z-ga rated this answer:5 out of 5 stars

Comments  
Subject: Re: Printing HTML tables - how to prevent cell splitting?
From: mvguy-ga on 17 Feb 2003 10:34 PST
 
I'm not sure it's possible (but I'd be glad to be proven wrong, which
is why I'm posting this as a comment rather than an answer). Many
people design pages using one large table with numerous embedded
tables, so many pages would be unprintable if browsers didn't break up
tables to print.

One possibility if you're printing pages is to use the Opera browser,
which lets you view and print pages at reduced sizes (even 20
percent). Internet Explorer lets you reduce the type size, which might
be sufficient to keep all of a table on one page.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy