页码和分页
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.11刚刚发布