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ヘッダー & フッターを追加

PDF 文書をレンダリングする際に、HTML ヘッダーとフッターを含むようにレンダリングオプションを設定します。 IronPDF は、PDF の高度な生成と操作を可能にする Iron Software のライブラリです。

仕切り線とHTMLフラグメントを含むヘッダーコンテンツを定義し、IronPdf の柔軟なPDFレンダリングツールを使用してヘッダーの最大高さを指定します。 IronPDFによって提供される htmlHeader プロパティを使用して同様にフッターコンテンツを定義します。

ヘッダーとフッターの高さは自動的に検出されないため、メインの HTML コンテンツと重なる可能性があることに注意してください。 ヘッダーとフッターが適切に配置されるようにマージンをカスタマイズします。

GitHub で HTML ヘッダーとフッターのコード例を調べる
GitHubで見る

準備はできましたか?

バージョン:2026.11リリースされたばかり