This document demonstrates how to add professional headers and footers to your PDF documents using mPDF.
Content Area
This is the main content area of the document. The header and footer will appear on every page automatically.
You can add as much content as needed, and mPDF will handle the page breaks and maintain the header/footer on each page.
Template File: This content is now loaded from an external HTML file located at
resources/views/mpdf/headers-footers.html
Second Page
This is the second page to demonstrate that headers and footers appear consistently across multiple pages.
Advanced Features:
- Dynamic content: Headers and footers can include dynamic content like page numbers, dates, etc.
- Different headers: You can set different headers for odd/even pages or first page
- HTML formatting: Full HTML and CSS support in headers and footers
- Margins: Customizable margins for header, footer, and content areas
- External Templates: HTML content can be loaded from separate files for better organization
Tip: Use the {PAGENO} and {nbpg} placeholders for automatic page numbering. You can also use {DATE} for current date
and other built-in variables.
Template Benefits:
- Better code organization and separation of concerns
- Easier maintenance and updates
- Reusable templates across different controllers
- Better collaboration between developers and designers
- Version control for template changes
Margin Configuration:
This document uses custom margins:
- Left margin: 20mm
- Right margin: 15mm
- Top margin: 48mm (includes header space)
- Bottom margin: 25mm (includes footer space)
- Header margin: 10mm
- Footer margin: 10mm