The second issue is headers and footers. HTML and Excel don't have them, but PDF does.
As per my earlier post -- you can utilize the proposed W3 extensions for this. For example, see this fragment taken from CSS Print to put a running page count at the bottom of pages:
font-family: Times, Palatino, serif;
content: "Page " counter(pages);
Sure, a lot of these standards are proposed/preliminary, but I think they offer a good place to start because a group of people have already been thinking about these sorts of challenges.
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.