Page headers and footers
Add custom headers and footers to each page of your PDF with dynamic content like page numbers and dates
The header_template
and footer_template
parameters allow you to add custom HTML content to the top and bottom of each page in your PDF.
Overview
When generating PDFs, it’s often useful to include consistent headers and footers on each page. These templates support special CSS classes for dynamic content like page numbers, dates, and titles.
Parameter details
HTML content to display at the top of each page
Note: render_header_footer
must be set to true
for this template to take effect
HTML content to display at the bottom of each page
Note: render_header_footer
must be set to true
for this template to take effect
Must be set to true
for header and footer templates to be rendered
Usage
Special CSS classes
Both templates support these special CSS classes for dynamic content:
date
: Current date when the PDF is generatedtitle
: Title of the document (from the HTML<title>
tag)url
: URL of the page being renderedpageNumber
: Current page numbertotalPages
: Total number of pages in the document
Styling guidelines
- Templates must contain valid HTML
- Use inline styles for consistent rendering
- Set explicit width (usually
width: 100%
) for proper alignment - Keep content within reasonable height to avoid overlapping with main content
- Use font sizes appropriate for headers/footers (typically 8-12px)
Use cases
These parameters are particularly useful for:
- Professional documents: Add company logos, document titles, and page numbers
- Reports: Include generation date, version information, and pagination
- Legal documents: Add disclaimers, confidentiality notices, or document identifiers
- Printed materials: Include contact information or copyright notices