views:

756

answers:

4

Hello all:

Based on my research, it seems that what I want to do is not possible, but in case something has changed, I wanted to check to see if anyone had come up with a way to do this.

I have a web app that generates reports for print based on user selections in the browser window. I have a custom header and footer that, when the report is printed from the browser, should be repeated on every printed page. It is not the browser header and footer I need, but rather the custom ones that I generate. Also, I don't think this is an issue of CSS and media types, but I am not a CSS expert. I have no issues getting the header and footer to print once, but I can't get them to print on each page. I have read that perhaps if I recreated my report pages using tables, and then used table head tags and CSS, that may work at least to get the header on each page. I have not had success with this yet, but I will try it again if it is the only option. A coworker suggested that I count lines in my php and manually put out the header and footer as required. I guess that is an option, but it just seems like there should be a way to do this that isn't so "brute force"!

The other caveat is that I have to support IE 6, so I suspect some of the CSS things I have tried are just not supported.

If anyone knows any way to do this, that would be great! If there isn't, I will have to rethink my approach.

Thanks in advance!

A: 

This will work in some browsers, not not all. I don't think there is an elegant cross-browser solution

Include the print footer/header you want in divs on the page (in this example div id='printableFooter')

In the screen css file put:

#printableFooter {display: none;}

In the print css file:

#printableFooter {display: block; position: fixed; bottom: 0;}
UpTheCreek
I will give this a try, although I thought position:fixed didn't work in IE 6? Still I will try it. Thanks.
Carvell Fenton
No, it won't work in ie6 unfortunately.
UpTheCreek
Sorry, just read your ie6 requirement! I guess that rules this one out :(
UpTheCreek
+1  A: 

I would suggest to divide the page in table, and add the header part to first row and the footer part to the last row. The contents of the rows between the first and last rows can be changed dynamically so you will get the constant header and footer at desired pages.

----------
ROW1    HEADER
----------
ROW2   
 Insert dynamic contents here
ROW N-1
----------
ROW N Footer


Sachin Chourasiya
Don't use tables for layout.
Jacob R
don't mindlessly downvote. it's a viable solution to the problem.
nickf
I agree about not down voting. This may be my only option if I can get it working in IE 6. I know that a general rule is not to use tables for layout in the modern web world, but this is a special case I think.
Carvell Fenton
Unfortuantly this won't work if the output paper size is variable -- you need to know the number of rows that a piece of A4 can take. And A3. And Legal. And Letter. And if the font size changes, you need to recalculate the rows again.
Chris J
I think this could be last solution to your problem, please tell me the reason for downvoting me
Sachin Chourasiya
There is no problem in using tables in this case, in fact, tables are for tabulation.
Horacio N. Hdez.
Thanks Sachin, your answer was helpful too, but I selected Chris J's because his was a little more "complete" and had the CSS I needed too. Thanks for your help!
Carvell Fenton
@Carvell, Its ok, we are here to help each other :)
Sachin Chourasiya
A: 

try to generate a (rtf | pdf) document for printing

Horacio N. Hdez.
I wanted to avoid generating additional document types because once the report is printed, I ideally don't want a file stored anywhere. I guess a temp pdf might be an option, but then it is easier for people to save that document, and I need to avoid that, or at least make it inconvenient to do.
Carvell Fenton
hi carvell, users can still download the webpage, it you automate with a tmp pdf file the process usability is not really affected, you can provide the html view and for printing the pdf :)
Horacio N. Hdez.
So for the printing you mean the pdf only exists in the "background" and is not seen by the user?
Carvell Fenton
yes, just for the printing, you launch a new tab or window with the location of the generated pdf, is the Reader is installed you should get a nice view that has the print option.
Horacio N. Hdez.
+3  A: 

It can be done with tables -- and I know I'm going to risk a downvote by suggesting using tables for layout - but we are talking IE6 here which isn't known for its fantastic CSS support :-)

If you set a CSS style as follows:

thead { display: table-header-group; }
tfoot { display: table-footer-group; }

Then when you create your HTML, render your body as:

<body>
<table>
   <thead><tr><td>Your header goes here</td></tr></thead>
   <tbody>
     <tr><td>
     Page body in here -- as long as it needs to be
     </td></tr>
   </tbody>
   <tfoot><tr><td>Your footer goes here</td></tr></tfoot>
</table>
</body>

Yes it's not good (tables vs CSS), it's not ideal, but (importantly for you) it does work on IE6. I can't comment on Firefox as I've not tested it there, but it should do the job. This will also handle differnt sized pages, differing font sizes, etc. so it should "just work".

If you want the header and footer to appear on printed media only, then use the @media parameters to do the right thing:

@media print {
    thead { display: table-header-group; }
    tfoot { display: table-footer-group; }
}
@media screen {
    thead { display: none; }
    tfoot { display: none; }
}
Chris J
Thanks Chris J. I know that are are not supposed to be using tables these days, but this work around does exactly what I needed, and saves me doing madness like counting lines! Using tables for just this specific purpose in the site might not be "so" bad? :) Thanks again!
Carvell Fenton
The only problem with this is that tfoot needs to come right after thead (before tbody) ;)
SeanJA