如何使用 IronPDF 在 PDF 中新增頁首與頁尾

使用 C# 和 IronPDF 在 PDF 中新增頁首與頁尾

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF 讓您能夠透過 來為 PDF 文件添加頁首和頁尾,用於簡單文字;或使用 適用於支援完整 CSS 樣式的 HTML 內容。 這項強大的功能對於建立具備一致品牌形象、頁碼編排及文件元資料的 Professional PDF 檔案至關重要。

需要在 PDF 文件的每頁頂部或底部加入頁碼、公司標誌或日期嗎? IronPDF 讓您能在 C# 專案中輕鬆為 PDF 檔案套用頁首與頁尾。 無論您是製作報告、發票或任何商業文件,頁首與頁尾皆提供關鍵的導覽與識別元素,能有效提升文件的易用性。

快速入門:在 C# 中為 PDF 添加頁首與頁尾

使用 C# 中的 IronPDF,輕鬆為您的 PDF 文件添加頁首和頁尾。 本指南將示範如何在數秒內套用包含頁碼與自訂文字的文字型頁首及頁尾。 使用 方法,可快速提升您的 PDF 呈現效果。 節省程式碼,以更新後的 PDF 儲存文件,確保文件呈現專業品質。

  1. using NuGet 套件管理員安裝 https://www.nuget.org/packages/IronPdf

    PM > Install-Package IronPdf
  2. 請複製並執行此程式碼片段。

    new IronPdf.ChromePdfRenderer { RenderingOptions = { TextHeader = new IronPdf.TextHeaderFooter { CenterText = "Report • {date}" }, TextFooter = new IronPdf.TextHeaderFooter { RightText = "Page {page} of {total-pages}" } } }
        .RenderHtmlAsPdf("<h1>Hello World!</h1>")
        .SaveAs("withHeadersFooters.pdf");
  3. 部署至您的生產環境進行測試

    立即透過免費試用,在您的專案中開始使用 IronPDF

    arrow pointer

如何新增文字頁首/頁尾?

若要建立僅含文字的頁首/頁尾,請建立 物件,加入所需文字,並將該物件加入您的 PDF 檔案中。 類別提供了一種簡便的方法,可在文件的所有頁面中添加一致的文字元素。 此方法特別適用於無需複雜格式或樣式的簡單頁首與頁尾。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-add-textheaderfooter.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create text header
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

// Create text footer
TextHeaderFooter textFooter = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Add text header and footer to the PDF
pdf.AddTextHeaders(textHeader);
pdf.AddTextFooters(textFooter);

pdf.SaveAs("addTextHeaderFooter.pdf");
Imports IronPdf

' Instantiate renderer and create PDF
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create text header
Dim textHeader As New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

' Create text footer
Dim textFooter As New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

' Add text header and footer to the PDF
pdf.AddTextHeaders(textHeader)
pdf.AddTextFooters(textFooter)

pdf.SaveAs("addTextHeaderFooter.pdf")
$vbLabelText   $csharpLabel

如何在渲染時加入頁首/頁尾?

此外,您亦可直接使用渲染器的 `` 來新增頁首/頁尾。 此方法會在渲染過程中加入文字頁首與頁尾,相較於在 PDF 建立後再添加,效率更高。 當您事先知曉頁首與頁尾內容時,建議採用此方法,因為這能縮短處理時間,並從一開始就確保格式的一致性。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-render-with-textheaderfooter.cs
using IronPdf;

// Instantiate renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Create header and add to rendering options
renderer.RenderingOptions.TextHeader = new TextHeaderFooter
{
    CenterText = "This is the header!",
};


// Create footer and add to rendering options
renderer.RenderingOptions.TextFooter = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Render PDF with header and footer
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
pdf.SaveAs("renderWithTextHeaderFooter.pdf");
Imports IronPdf

' Instantiate renderer
Dim renderer As New ChromePdfRenderer()

' Create header and add to rendering options
renderer.RenderingOptions.TextHeader = New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

' Create footer and add to rendering options
renderer.RenderingOptions.TextFooter = New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

' Render PDF with header and footer
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")
pdf.SaveAs("renderWithTextHeaderFooter.pdf")
$vbLabelText   $csharpLabel

如何自訂文字和分隔線的屬性?

在 `` 類別中,您可以設定左、中、右三種位置的文字。 此外,您可透過設定相關屬性,自訂文字的字型與大小,並加入自訂顏色的分隔線。 這些自訂選項可讓您建立符合企業品牌形象或文件樣式指南的頁首與頁尾。 分隔線功能特別適用於在頁首/頁尾與主要內容之間建立視覺上的區隔。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-textheaderfooter-options.cs
using IronPdf;
using IronPdf.Font;
using IronSoftware.Drawing;

// Create text header
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "Center text", // Set the text in the center
    LeftText = "Left text", // Set left-hand side text
    RightText = "Right text", // Set right-hand side text
    Font = IronSoftware.Drawing.FontTypes.ArialBoldItalic, // Set font
    FontSize = 16, // Set font size
    DrawDividerLine = true, // Draw Divider Line
    DrawDividerLineColor = Color.Red, // Set color of divider line
};
Imports IronPdf
Imports IronPdf.Font
Imports IronSoftware.Drawing

' Create text header
Private textHeader As New TextHeaderFooter With {
	.CenterText = "Center text",
	.LeftText = "Left text",
	.RightText = "Right text",
	.Font = IronSoftware.Drawing.FontTypes.ArialBoldItalic,
	.FontSize = 16,
	.DrawDividerLine = True,
	.DrawDividerLineColor = Color.Red
}
$vbLabelText   $csharpLabel

自訂的文字標題呈現為何樣貌?

文字對齊範例,展示左對齊、居中及右對齊的文字定位選項

預設提供哪些字型?

您可參閱 IronPDF API 參考文件,了解預設可用的字型類型。 IronPDF 支援多種標準字型,包括 Arial、Times New Roman、Helvetica、Courier 及其變體。 若需使用自訂字型,請進一步了解如何在 IronPDF 中管理字型。

如何設定文字頁首/頁尾的邊距?

預設情況下,IronPDF 中的文字頁首和頁尾會預設邊界。 若希望文字標題橫跨 PDF 文件的整個寬度,請將邊距值設定為 0。這可透過在 函式中直接設定邊界,或透過 中的 來達成。 理解邊距控制對於實現像素級精準的版面配置至關重要,特別是在處理自訂紙張尺寸時。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-textheaderfooter-margins.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

TextHeaderFooter header = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

TextHeaderFooter footer = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

pdf.AddTextHeaders(header, 35, 30, 25); // Left Margin = 35, Right Margin  = 30, Top Margin = 25
pdf.AddTextFooters(footer, 35, 30, 25); // Margin values are in mm
Imports IronPdf

' Instantiate renderer and create PDF
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

Dim header As New TextHeaderFooter With {
    .CenterText = "This is the header!"
}

Dim footer As New TextHeaderFooter With {
    .CenterText = "This is the footer!"
}

pdf.AddTextHeaders(header, 35, 30, 25) ' Left Margin = 35, Right Margin = 30, Top Margin = 25
pdf.AddTextFooters(footer, 35, 30, 25) ' Margin values are in mm
$vbLabelText   $csharpLabel

如何透過渲染選項設定邊距?

若在 中的 設定邊距值,這些邊距亦將套用至頁首與頁尾。 此方法提供了一種集中管理整個文件邊距的方式,包括頁首、頁尾及主要內容。 如需更進階的邊距自訂功能,請參閱我們的自訂邊距設定指南。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-rendering-options-margins.cs
using IronPdf;

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

TextHeaderFooter header = new TextHeaderFooter
{
    CenterText = "This is the header!",
};

TextHeaderFooter footer = new TextHeaderFooter
{
    CenterText = "This is the footer!",
};

// Margin values are in mm
renderer.RenderingOptions.MarginRight = 30;
renderer.RenderingOptions.MarginLeft = 30;
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;

// Add header and footer to renderer
renderer.RenderingOptions.TextHeader = header;
renderer.RenderingOptions.TextFooter = footer;

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
Imports IronPdf

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()

Private header As New TextHeaderFooter With {.CenterText = "This is the header!"}

Private footer As New TextHeaderFooter With {.CenterText = "This is the footer!"}

' Margin values are in mm
renderer.RenderingOptions.MarginRight = 30
renderer.RenderingOptions.MarginLeft = 30
renderer.RenderingOptions.MarginTop = 25
renderer.RenderingOptions.MarginBottom = 25

' Add header and footer to renderer
renderer.RenderingOptions.TextHeader = header
renderer.RenderingOptions.TextFooter = footer

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")
$vbLabelText   $csharpLabel

為何應避免使用 ``?

物件上的 屬性不適用於此使用情境。 它將相同的邊距值套用至頁首、頁尾和主要內容,這可能會導致頁首與文件正文重疊。 此屬性主要用於透過 `` 方法,在現有 PDF 檔案中加入頁首與頁尾。 為更好地控制版面配置,建議使用分頁符號來管理內容流。

何謂動態邊距設定?

當不同文件中的頁首內容有所差異時,固定邊距會造成問題。 為適應不同的頁首與頁尾尺寸,不僅需調整頁首與頁尾的邊距,還需調整主 HTML 區塊的邊距。 因此,我們實作了"動態邊距調整"功能,讓頁首與頁尾的高度能根據內容動態調整,並讓主 HTML 內容隨之重新定位。 此功能在處理響應式 CSS 佈局時特別有用。 請使用以下程式碼試用此功能:

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-dynamic-marigns.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = @"<div style='background-color: #4285f4; color: white; padding: 15px; text-align: center;'>
                    <h1>Example header</h1> <br>
                    <p>Header content</p>
                    </div>",
    // Enable the dynamic height feature
    MaxHeight = HtmlHeaderFooter.FragmentHeight,
};

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");
pdf.SaveAs("dynamicHeaderSize.pdf");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
	.HtmlFragment = "<div style='background-color: #4285f4; color: white; padding: 15px; text-align: center;'>
                    <h1>Example header</h1> <br>
                    <p>Header content</p>
                    </div>",
	.MaxHeight = HtmlHeaderFooter.FragmentHeight
}

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")
pdf.SaveAs("dynamicHeaderSize.pdf")
$vbLabelText   $csharpLabel

如何在文字頁首/頁尾中加入元資料?

您可透過在文本中加入佔位字串,輕鬆添加頁碼、日期及 PDF 標題等元資料。 這些佔位符會在渲染 PDF/A 時自動替換為對應的值。 此功能對於建立能根據文件屬性自動更新的動態頁首與頁尾至關重要。 以下為所有可用的元資料選項:

  • ``:當前頁碼。
  • ``:總頁數。
  • ``:渲染 PDF 文件的來源網頁網址。
  • ``:當前日期。
  • ``:當前時間。
  • :HTML 標籤 中指定的 HTML 標題。
  • ``:PDF 元資料中指定的 PDF 標題。

我應該最常使用哪些佔位符?

如需進一步了解 ,請參閱 IronPDF 頁碼指南。 這些佔位符因提供關鍵的導覽資訊,而成為最常被使用的選項。 日期與時間占位符對於需要追蹤時間戳記的文件(例如報告或發票)特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-mail-merge.cs
using IronPdf;

// Create header and footer
TextHeaderFooter textHeader = new TextHeaderFooter
{
    CenterText = "{page} of {total-pages}",
    LeftText = "Today's date: {date}",
    RightText = "The time: {time}",
};

TextHeaderFooter textFooter = new TextHeaderFooter
{
    CenterText = "Current URL: {url}",
    LeftText = "Title of the HTML: {html-title}",
    RightText = "Title of the PDF: {pdf-title}",
};
Imports IronPdf

' Create header and footer
Private textHeader As New TextHeaderFooter With {
	.CenterText = "{page} of {total-pages}",
	.LeftText = "Today's date: {date}",
	.RightText = "The time: {time}"
}

Private textFooter As New TextHeaderFooter With {
	.CenterText = "Current URL: {url}",
	.LeftText = "Title of the HTML: {html-title}",
	.RightText = "Title of the PDF: {pdf-title}"
}
$vbLabelText   $csharpLabel

如何新增 HTML 頁首/頁尾?

您可以透過使用 HTML 和 CSS 進一步自訂頁首/頁尾。 若要建立 HTML 頁首/頁尾,請使用 類別。 此方法提供最大的靈活性,讓您能在頁首和頁尾中加入圖片、複雜的版面配置以及格式化的內容。 若您希望保留 CSS 樣式表中的樣式,請在類別屬性中設定LoadStylesAndCSSFromMainHtmlDocument = true``。 這在處理網頁字型和圖示時特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter.cs
using IronPdf;

string headerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>";

string footerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>";

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create header and footer
HtmlHeaderFooter htmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = headerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = footerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

// Add to PDF
pdf.AddHtmlHeaders(htmlHeader);
pdf.AddHtmlFooters(htmlFooter);
Imports IronPdf

Private headerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>"

Private footerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>"

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create header and footer
Private htmlHeader As New HtmlHeaderFooter With {
	.HtmlFragment = headerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

Private htmlFooter As New HtmlHeaderFooter With {
	.HtmlFragment = footerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

' Add to PDF
pdf.AddHtmlHeaders(htmlHeader)
pdf.AddHtmlFooters(htmlFooter)
$vbLabelText   $csharpLabel

如何控制 HTML 頁首/頁尾的邊距?

與文字頁首和頁尾類似, 方法已預設了邊距。 若要套用自訂邊距,請使用帶有指定邊距值的函式重載版本。 若要讓內容完全填滿頁面且無邊距,請在重載函式中將邊距設定為 0。在製作具有特定版面配置要求的 Professional 文件時,此類精細控制至關重要。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter-margins.cs
// Add to PDF
pdf.AddHtmlHeaders(header, 0, 0, 0);
pdf.AddHtmlFooters(footer, 0, 0, 0);
' Add to PDF
pdf.AddHtmlHeaders(header, 0, 0, 0)
pdf.AddHtmlFooters(footer, 0, 0, 0)
$vbLabelText   $csharpLabel

渲染時可以添加 HTML 頁首/頁尾嗎?

亦可透過渲染器的 `` 直接新增頁首與頁尾。 此功能會在渲染過程中加入 HTML 頁首與頁尾,相較於後製處理更為高效。 此方法在將 HTML 檔案轉為 PDF 或進行 URL 轉 PDF 轉換時特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/headers-and-footers-htmlheaderfooter.cs
using IronPdf;

string headerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>";

string footerHtml = @"
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>";

// Instantiate renderer and create PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");

// Create header and footer
HtmlHeaderFooter htmlHeader = new HtmlHeaderFooter
{
    HtmlFragment = headerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

HtmlHeaderFooter htmlFooter = new HtmlHeaderFooter
{
    HtmlFragment = footerHtml,
    LoadStylesAndCSSFromMainHtmlDocument = true,
};

// Add to PDF
pdf.AddHtmlHeaders(htmlHeader);
pdf.AddHtmlFooters(htmlFooter);
Imports IronPdf

Private headerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a header!</h1>
    </body>
    </html>"

Private footerHtml As String = "
    <html>
    <head>
        <link rel='stylesheet' href='style.css'>
    </head>
    <body>
        <h1>This is a footer!</h1>
    </body>
    </html>"

' Instantiate renderer and create PDF
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")

' Create header and footer
Private htmlHeader As New HtmlHeaderFooter With {
	.HtmlFragment = headerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

Private htmlFooter As New HtmlHeaderFooter With {
	.HtmlFragment = footerHtml,
	.LoadStylesAndCSSFromMainHtmlDocument = True
}

' Add to PDF
pdf.AddHtmlHeaders(htmlHeader)
pdf.AddHtmlFooters(htmlFooter)
$vbLabelText   $csharpLabel

何時該使用純文字,何時該使用 HTML 頁首/頁尾?

在決定採用文字或 HTML 頁首/頁尾時,請權衡其利弊。 若您優先考量更快的 PDF 渲染速度,請選擇"文字"頁首/頁尾。 若需自訂樣式,請選用 HTML 頁首/頁尾。 當 HTML 頁首/頁尾的內容有限時,其與純文字頁首/頁尾之間的渲染時間差異極小。 然而,隨著 HTML 頁首/頁尾中資產的大小與數量增加,其複雜度也會隨之提升。

這會對效能產生什麼影響?

文字頁首/頁尾的渲染速度較快,因為它們無需進行 HTML 解析和 CSS 處理。 HTML 頁首/頁尾雖提供更大的靈活性,但其渲染時間會隨複雜度增加而相應增加。 在處理大型文件或進行批次處理時,效能差異會更加明顯。 若需在大量處理情境下獲得最佳效能,請參考我們關於非同步 PDF 生成的指南。

準備好探索更多可能性了嗎? 請點此查看我們的教學頁面:建立 PDF 檔案

常見問題

如何在 C# 中為 PDF 檔案新增頁首和頁尾文字?

透過 IronPDF,您可以使用 AddTextHeaders 和 AddTextFooters 方法新增文字頁首與頁尾。只需建立 TextHeaderFooter 物件,加入所需文字,並套用至 PDF 即可。這提供了一種簡便的方式,可在所有頁面中添加一致的文字元素,例如頁碼或文件標題。

我可以在 PDF 的頁首或頁尾加入頁碼嗎?

是的,IronPDF 支援透過特殊佔位符進行動態頁碼編號。您可以在 TextHeaderFooter 物件中使用 {page} 表示當前頁碼,以及 {total-pages} 表示總頁數。例如,設定 RightText = "第 {page} 頁,共 {total-pages} 頁" 將自動在每頁顯示正確的頁碼。

是否可以加入採用 CSS 樣式的 HTML 格式頁首與頁尾?

沒問題!IronPDF 提供了 AddHtmlHeaders 和 AddHtmlFooters 方法,讓您能夠添加支援完整 CSS 樣式的 HTML 內容。這使您能夠建立包含格式化文字、圖片及自訂樣式的複雜頁首與頁尾,以符合您的品牌規範。

在 PDF 中添加頁首和頁尾最有效率的方法是什麼?

最有效率的方法是在渲染過程中,透過 IronPDF 的 RenderingOptions 來添加頁首和頁尾。若在渲染前於 ChromePdfRenderer 中設定 TextHeader 和 TextFooter 屬性,相較於在 PDF 建立後再添加,可有效縮短處理時間。

我可以在頁首/頁尾的左、中、右三個區塊中加入不同的內容嗎?

是的,IronPDF 中的 TextHeaderFooter 類別提供了 LeftText、CenterText 和 RightText 屬性,讓您能在每個區段中放置不同的內容。這讓您能靈活地安排資訊,例如將日期置於左側、標題置於中央,以及頁碼置於右側。

如何將公司標誌加入 PDF 頁首?

若要在 PDF 頁首加入公司標誌,請使用 IronPDF 中的 AddHtmlHeaders 方法。您可以在 HTML 內容中加入指向標誌檔案的 image 標籤,並透過 CSS 進行額外的樣式設定或定位,以確保標誌精確顯示在您期望的位置。

我可以在 PDF 的頁首和頁尾中加入日期嗎?

是的,IronPDF 支援透過 TextHeaderFooter 物件中的 {date} 佔位符來動態插入日期。當您在頁首或頁尾文字中包含 {date} 時,系統會在產生 PDF 時自動將其替換為當前日期。

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
Nuget 下載 19,014,616 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPdf
執行範例 觀看您的 HTML 轉為 PDF。