IRONSOFTWAREHOME
页码和分页
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    const html = `
        <p> Hello Iron</p>
        <p> This is 1st Page </p>
        <div style='page-break-after: always;'></div>
        <p> This is 2nd Page</p>
        <div style='page-break-after: always;'></div>
        <p> This is 3rd Page</p>
    `;

    // Configure render options
    const options = {
        htmlHeader: {
            htmlFragment: "<center><i>{page} of {total-pages}<i></center>",
            dividerLine: true,
            maxHeight: 15,
        }
    };

    const pdf = await PdfDocument.fromHtml(html, {renderOptions: options});

    // Save the PDF
    await pdf.saveAs("pageNumber.pdf");
})();
npm i @ironsoftware/ironpdf
页码和分页

页码和分页

在使用IronPDF渲染为PDF时,HTML中的分页符完美地工作。

在HTML中,分页符是一个标记或指令,告诉网络浏览器或渲染引擎在显示或打印内容时开始新页面。 在您希望控制打印文档的布局或确保某些内容从新页面开始时,通常会使用分页符。

此外,下面的代码配置了渲染选项,以在PDF文档底部中心包含页码。 页码显示格式为"{page} of {total-pages}",并限于最大高度15个单位。

有关在将HTML转换为PDF时高效管理分页符的更多信息,请参考IronPDF功能的综合指南。 IronPDF 是由 Iron Software 提供的一套强大的工具的一部分,专为各种文件处理需求而量身定制,包括 使用 IronBarcode 生成条形码、通过 IronXL 操作 Excel 表格以及 使用 IronOCR 进行光学字符识别。

探索 PDF 中页码和分隔符的代码示例
在 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 起