Add Classic Text Headers & Footers

Learn how to add text headers and footers to a PDF document when rendering HTML content.

To include text headers and footers, you need to specify them in the rendering options object. Define the header content with a divider line, centered text displaying the HTML title, font settings, and font size. Similarly, define the footer with the textFooter property. You can utilize fields like {page}, {total-pages}, {url}, {date}, {time}, {html-title}, and {pdf-title} to personalize the content.

Customize margins to accommodate the header and footer appropriately.

Utilize the PdfDocument.fromHtml method to convert your HTML content into a PDF. Pass the renderOptions object as an option.

The resulting PDF document, complete with headers and footers, is saved under the name "header_footer.pdf."