Is it possible to print HTML pages with custom headers and footers on each printed page?
I'd like to add the word "UNCLASSIFIED" in Red, Arial, size 16pt to the top and bottom of every printed page, regardless of the content.
To clarify, if the document was printed onto 5 pages, each page should have the custom header and footer.
Does anybody know if this is possible using HTML/CSS?
If you don;t need the formatting use
document.title
and that works like charm in every major browser (tested in Chrome , IE 11, Firefox).Or you can use
the magic solution is really putting every thing in single table.
thead: this is for the repeated header.
tfoot: the repeated footer.
tbody: the content.
and make a single tr, td and put every thing in a div
CODE::
extra: to prevent overlapping with multiple pages. like:
which results in overflow that will make things overlap with the header within the page breaks..
so >> use:
page-break-inside: avoid !important;
with this classarticle
.pretty simple, hope this will give you the best result you wishing for.
best regards. ;)
If you can use javascipt, have the client handle laying out the content using javascript to place elements based on available space.
You could use the jquery columnizer plugin to dynamically lay out your content in fixed size blocks and position your headers and footers as part of the rendering routine. http://welcome.totheinter.net/columnizer-jquery-plugin/
See example 10 http://welcome.totheinter.net/autocolumn/sample10.html
The browser will still add its own headers or footers if enabled in the os. Consistent layout across platforms and browsers will likely require conditional css.
If you are using a template engine like Asp.net Razor Engine or Angular, I think you must re-generate your page and split the page in several pages and then you can freely markup each page and put header and footer on theme. one example could be as bellow:
Is this something you want to print-only? You could add it to every page on your site and use CSS to define the tag as a print-only media.
As an example, this could be an example header:
And in your CSS, do something like this:
Finally, to include the header/footer on every page you might use server-side includes or if you have any pages being generated with PHP or ASP you could simply code it in to a common file.
Edit:
This answer is intended to provide a way to show something on the physical printed version of a document while not showing it otherwise. However just as comments suggest, it doesn't solve the issue of having a footer on multiple printed pages when content overflows.
I'm leaving it here in case it's helpful nevertheless.
Use page breaks to define the styles in CSS:
Then add the markup in the document at the appropriate places:
References
CSS Paged Media: Page Breaks
MDN: page-break-before
MDN: break-before
Multi-column Layout
XHTML Print: Second Edition
Webkit Bug 5097: CSS2 page-break-after does not work
Print HTML FAQ: Will the program respect CSS styles such as page-break-after?
How to deal with page breaks when printing a large HTML table