Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print header/footer on all pages (Print Mode)

<div id="header">header</div>
<div id="content">
    content spanning several pages...
</div>
<div id="footer">Footer - Fixed at the bottom of each page</div>

I want to print #header and #footer on every page in print mode. I searched a lot but nothing seems to work, even position:fixed doesn't work as expected.

like image 540
eozzy Avatar asked Dec 02 '11 13:12

eozzy


People also ask

How do I set up headers and footers to print on all pages?

Click the Effects menu on the Detailed Settings tab. Select the Header/Footer check box. Select the items that you want to print on header and footer, Date and Time, Page Number, and Text.

How do I make the footer appear when I print?

In the File tab, click Print, click Page Setup, and then click the Legend tab. Under Legend on, click Every page, Legend page, or None. See Customize printing of a legend or title for more information. The header and footer that you set will appear on every page.

How do you add a header and footer when printing?

To create a header or footer Click the Printer tab. Select Header or Footer. Enter any text you want to appear in the header or footer in the Header/Footer text field. Optional: Use the information in the table below to insert page numbers, total number of pages, date, time, tab, or title automatically.

Why is my printer not printing headers and footers?

The most common cause of this problem is that the bottom margin, footer margin, or page border is outside the printable area of the page. All printers have an irreducible unprintable area necessitated by the mechanical requirements of paper handling.


3 Answers

If you're willing to switch over to tables for your layout (not necessarily ideal), you can do it with the <thead> and <tfoot> elements. They'll print at the top and bottom of every page:

<table>

  <thead>
     <!-- Will print at the top of every page -->
  </thead>

  <tbody>
     <!-- Page content -->
  </tbody>

  <tfoot>
     <!-- Will print at the bottom of every page -->
  </tfoot>

</table>

Another option is to use display table-header-group and table-footer-group but cross-browser support isn't great:

#header {
  display: table-header-group;
}

#main {
  display: table-row-group;
}

#footer {
  display: table-footer-group;
}
like image 174
Pat Avatar answered Oct 27 '22 05:10

Pat


I think I arrived too late :), but I was looking for something like this, and I found one answer that helps me (source https://www.youtube.com/watch?v=yDgFLysON98). I wrote the div tag before and after the content like this

<div id="header">Top div content</div>

.
.
.
<div id="footer">Bottom div content</div>

Example:

<!DOCTYPE html>
<html>
<head>``
<style>
body {
    background-color: #CCC;
    margin:48px 0px 0px 64px;
}
div#header {
    position:fixed;
    top:0px;
    left:0px;
    width:100%;
    color:#CCC;
    background:#333;
    padding:8px;
}
div#footer {
    position:fixed;
    bottom:0px;
    left:0px;
    width:100%;
    color:#CCC;
    background:#333;
    padding:8px;
}
</style>
</head>
<body>
<div id="header">HEADER</div>
<h1>Page Heading</h1>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<p>Content placeholder ...</p>
<div id="footer">FOOTER</div>
</body>
</html>

... I hope this helps.

like image 37
Oscar Albert Avatar answered Oct 27 '22 05:10

Oscar Albert


For that you need to use the mso (microsoft office css properties) in your style:

<style><--
@page 
{
    size:21cm 29.7cmt;
    margin:1cm 1cm 1cm 1cm; 
    mso-title-page:yes;
    mso-page-orientation: portrait;
    mso-header: header;
    mso-footer: footer;
}
@page content {margin: 1cm 1cm 1cm 1cm;}
div.content {page: content;}
</style>
like image 1
Vincent Teyssier Avatar answered Oct 27 '22 07:10

Vincent Teyssier