How to Print Web Page Headers and Footers on Every Page?

Barbara Streisand
Release: 2024-10-25 11:23:02
Original
242 people have browsed it

How to Print Web Page Headers and Footers on Every Page?

Printing Web Page Headers and Footers on Every Page

It is possible to ensure that custom headers and footers appear on every printed page from a web application. While initial research may suggest otherwise, explore the following solution:

Using Tables:

Create a table with a thead (for the header) and tfoot (for the footer) sections. Nesting these sections within the table allows for the dynamic rendering of headers and footers on each printed page.

CSS Styling:

Apply the following CSS styles to control the display of the header and footer:

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

Browser Compatibility:

This approach is ideal for IE6, which has limited CSS support. Note that Firefox is also expected to support it.

For printing-only visibility:

Use @media parameters to specify that the header and footer should only be visible on printed media:

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

@media screen {
  thead { display: none; }
  tfoot { display: none; }
}
Copy after login

Alternative Solution:

If the table approach does not meet your needs, consider generating reports in PDF format using tools like TCPDF. This method provides greater control over page formatting and ensures consistent rendering of headers and footers.

The above is the detailed content of How to Print Web Page Headers and Footers on Every Page?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!