IRONSOFTWAREHOME
新增 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.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費線上演示
Booking Badge

獲得來自全球數百萬工程師的信賴

Iron Software的客戶徽標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的資料將始終保密。
獲得來自全球數百萬工程師的信賴
Iron Software的客戶徽標
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
Node.js模組下載PDF
使用npm安裝

版本: 2026.6

  1. 下載並安裝Node.js 12+。
  2. 在終端機中執行上述命令。

授權從$999起