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页眉和页脚

配置渲染选项以在使用IronPDF进行PDF文档渲染时包含HTML页眉和页脚。IronPDF是Iron Software推出的库,允许进行高级PDF生成和操作。

通过使用IronPdf的灵活PDF渲染工具,定义带分割线、HTML片段的标题内容,并指定标题的最大高度。 同样,使用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
using npm 安装

版本: 2026.6

  1. 下载并安装 Node.js 12+。
  2. 在终端中执行上述命令。

$999 起