length of a paper.

jackie190
jackie190 used Ask the Experts™
on
I have generating some table for a html page.
I try to print a footer and a header every page.
The html code is generated dynamically by some java code. what's the best way to keep track of the no of row or how much i have printed in order to put a footer there? (counting the number of <tr>? number of <br>?) doesn't sound work.

any suggestion? thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Printing is handled by the browser, so each browser may print your pages slightly differently. I don't think it is possible to do what you want - not with HTML and JavaScript, anyway.
use a reporting tool instead on plain HTML if you want the advanced features of a document style output

Commented:
Here's a crude hack that works pretty well. Dump the output into a table, the height of which is controlled by spacer-images.

Since images are of a specific size (in pixels), you can effectively control page-height by stacking up a bunch of them and then allowing your table's height to flow with this stack. I used a column of invisible .gifs, 1px square....about 325 of them, plus my header.

I arrived at that by trial & error - printing a page and then adjusting my image-stack. I also fudged to allow for trouble caused by the viewer's font-settings. And its not a perfect solution. When you set up a page for 640x480, it looks 'short' at 1024x768.

Even so, I'm a layout-freak and my pages still looked great. Plus, no more worries that someone would find his printed copy had been awkwardly truncated, at page-bottom. So, I happily accepted any trade-offs. Hope it works equally well for you.

Mr F
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
thanks Mr F
Could you be more explicit? I kind of know how's working. but can you give me a really simple and short example? I really appreciated that. :)
Commented:
Ok - here's a quick example that certainly qualifies as simple and short:

<html>
<head></head>
<body>
<table width=635 align=center border=1>
<!-- Color & a border added for easier viewing -->
 <tr>
  <td width="100%" colspan=2 bgcolor="#ccccff"><img src="http://foo.com/images/our-logo.jpg" width=150 height=55 align=left><p>your header logo and whatever goes here</td>
 </tr>
 <tr>
  <td width="100%">here's your body text<br><br>and here's that dynamically-generated table</td>
  <td><img src="http://foo.com/images/spacer.gif" width=1 height=420></td>
 </tr>
 <tr>
  <td width="100%" colspan=2 bgcolor="#fffffc">your footer text goes here - blah, blah</td>
 </tr>
</table>
</body>
<!-- Obviously, I've left out lots of W3C niceties. Mea culpa. -->
</html>

Just add up the 'height' values. If I got it right, this page is ~640x480px....small enough so there's no need for L-to-R scrolling, yet reasonably capacious. Try it - its easily adjusted to 800x600 or whatever.

See where I'm calling a 1px-wide .gif named 'spacer'? That's the secret; it can be either visible or invisible, depending on your needs. Doesn't waste much space, either, tucked waaaay over there.

Hope this does it for you. I'd love to get some points, my first time out. :)

Mr F

Commented:
jackie190, just keep in mind that not all paper sizes are the same. Is this something only you are going to use, or a company, or is it open to the wider public? While the US uses letter size paper, other countries use A4.

Author

Commented:
hi Mr F,

but how i can added up all the height?
thanks!

- jack

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial