添加經典文本頁眉和頁腳

了解如何在渲染 HTML 內容時為 PDF 文件新增文字頁首和頁尾。

若要包含文字頁首和頁腳,需要在渲染選項物件中指定它們。 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.

調整頁邊距,使其與頁首和頁尾相符。

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

有關從 HTML 建立 PDF 的詳細文檔,請造訪IronPDF文檔

產生的 PDF 文件(包含頁首和頁尾)儲存為"header_footer.pdf"。

在GitHub上查看頁首和頁尾範例程式碼

準備好開始了嗎?
版本: 2026.3 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想要快速證明?
執行範例 觀看您的 HTML 變成 PDF。