Hai,
I've read about "page-break-inside" style and it seems to be
exactly what I need. I am working on some report printings, and I need
specific table to be printed on following page if it does not fit in the
current one. Unfortunatelly, I cannot solve this issue... Does
page-break-inside not work? I have made some tests on IE 7.0 and it
simply does nothing. How should I use this style?... Here is my code:

<table style="page-break-inside:avoid;">
<tr>
<td align="center" valign="middle">31</td>
<td align="center" valign="middle">32</td>
<td align="center" valign="middle" id="cell3">33</td>
<td align="center" valign="middle" id="cell1">13</td>
</tr>
</table>

Can you help me?
Thank you very much!

Seetha

I need specific table to be printed on following page if it does not fit in the current one. Unfortunatelly, I cannot solve this issue... Does page-break-inside not work? I have made some tests on IE 7.0 and it simply does nothing. How should I use this style?

Well you can not take a decision at run time that whether the table will fit on the page or not. So you can use any of the CSS property page-break-after, page-break-before or page-break-inside to insert page breaks. So either you will have to put page break at the beginning of the table of at the end of the table and you can not predict whether it should be before or after the table.

Hai

Thanks for the support.

BUt Im creating dynamic tables. The tables are not fixed size. One page may contain two or more tables. That is not specified in the program code. I cannot set page break before or after the tables, If I set means each table will print in one page. I dont want like that. If the table is not fit to the page, automatically it should go to the next page. I am using pagebreakinside in CSS. But it is not working... Any other way.

Thanks

Seetha

Hi,
dynamic width and dynamic number of tables is not possible, just as msaqib said, you have to make the decision about the page break before you put the style into css.

If you want to make both table width and page breaks dynamic, then you have to take a greater step, and make some calculation:

1. Define the width of the page
2. Define font size
3. Get approx. width of each character in that specific font size (width of i and width of w / 3 * 2).
4. Define the margins and paddings
5. Make calculation of the achieved width during page generation by:
counting characters, multiplying with average font-width, add margin and padding, set as achieved width of table.

Now prior to sending the whole stuff to the browser, you have to put the whole text into variables, so that you can calculate whether the next table fits in the space between the last table and the edge of the page.

If the table fits into the space, then put it there, else simply add a page break before the table.

This is a little complicated and takes time, but it's possible.

Good luck.

Thank you much. Now I am having clear idea. I will try this and reply back

Moderators need to move this to the CSS forum because i don't see how this fits into ASP.

Make the decision at print time by selecting the table, and then print only the selection.

The tables are not fixed size. One page may contain two or more tables. That is not specified in the program code. I cannot set page break before or after the tables, If I set means each table will print in one page. I dont want like that. If the table is not fit to the page, automatically it should go to the next page. I am using pagebreakinside in CSS. But it is not working... Any other way.

Not all printers are created equally.

You are having problems because the printer is not controlled by either the web browser or the html code. It is controlled by the printer driver that came with the printer. This function (and its settings) belongs to the owner of the computer rendering the page, not to you.

Your code can not know in advance how many lines the printer attached to the user's system can put on a page, or how the printer will lay out a table. It will be different if a user with a different printer opens the page. Just like different screen resolutions, there are different printer pixel resolutions.

So all of the rules that apply to different screens (and their disadvantages) also apply to different printers. Not only can't you know where the printer will break a page, you can't even know how large the printed page is, in terms of how much content fits on a page.

To get all of a table (or multiple tables) onto a page, the user should select the parts he wants to print, and then use Print Selection on the printer dialog box.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.