新增 HTML 頁首與頁尾
const {PdfDocument} = require("@ironsoftware/ironpdf");

(async () => {
    // Configure render options
    const renderOptions = {
        firstPageNumber: 1, // Use 2 if a cover page will be appended

        // Build a footer using html to style the text
        // mergeable fields are:
        // {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
        htmlFooter: {
            maxHeight: 15, //millimeters
            htmlFragment: "<center><i>{page} of {total-pages}<i></center>",
            dividerLine: true,
        },

        // Build a header using an image asset
        htmlHeader: {
            maxHeight: 15, //millimeters
            htmlFragment: "<img src='logo.png'>",
        },

        // Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
        margin: {
            top: 25, // Create 25mm space for the header
            bottom: 25, // Create 25mm space for the footer
        },
    };
})();
npm i @ironsoftware/ironpdf
新增 HTML 頁首與頁尾

新增 HTML 頁首與頁尾

設定渲染選項,以便在使用 Iron Software 提供的 IronPDF 庫(該庫支援進階 PDF 生成與處理)渲染 PDF 文件時,包含 HTML 頁首與頁尾。

請使用分隔線與 HTML 片段定義頁首內容,並透過 IronPdf 的彈性 PDF 渲染工具指定頁首的最大高度。 同樣地,請使用 IronPDF 提供的 htmlHeader 屬性來定義頁尾內容。

請注意,頁首與頁尾的高度不會自動偵測,這意味著它們可能會與主要 HTML 內容重疊。 請調整邊距,以確保頁首和頁尾的位置正確。

在 GitHub 上探索 HTML 頁首與頁尾的程式碼範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.11剛剛發布