跳過到頁腳內容
產品比較

QuestPDF向PDF添加頁碼的替代品VS IronPDF(示例)

Full Comparison

Looking for a detailed feature-by-feature breakdown? See how IronPDF stacks up against QuestPDF on pricing, HTML support, and licensing.

View Full Comparison

Portable Document Format (PDF) 是一種普遍使用的檔案格式,可確保所有平台和裝置上的文件呈現一致性。 其固定版面使其成為分享文件、合約、發票等的常用格式。 PDF 檔案是企業界不可或缺的正式文件。 隨著 PDF 生成和操作的需求日益增加,出現了幾個函式庫,簡化了開發人員的流程。

在本文中,我們將探討如何使用 QuestPDF 在 C# 中為 PDF 新增頁碼,同時也會比較 QuestPDF 與 IronPDF 的優劣,以協助您決定哪一個函式庫適合您的專案需求。

什麼是 IronPDF?

IronPDF 是專為 .NET 生態系統打造的功能豐富的函式庫,旨在高效處理 PDF 的建立、處理和渲染任務。 它利用基於 Chrome 的引擎,提供 HTML、CSS 和 JavaScript 至 PDF 文件的精確轉換。 因此,對於需要 將 HTML 內容直接轉換為 PDF 格式,同時保留原始版面與樣式的網頁開發人員而言,這是一個絕佳的選擇。

有了 IronPDF for .NET,您可以輕鬆地將 PDF 功能整合到您的 .NET 應用程式中,包括建立自訂的頁首與頁尾,為 PDF 新增頁面,嵌入圖片與表格,以及執行進階的 PDF 操作,例如合併或分割文件。 這個函式庫支援各種格式,並提供多種客製化選項,非常適合從動態網頁內容產生專業級 PDF。

IronPDF 的主要功能:

若要深入瞭解 IronPDF 的功能和更多進階範例,請參閱官方說明文件 這裡

安裝 IronPDF。

若要在專案中加入 IronPDF,請使用 Visual Studio 中的 NuGet 套件管理員。 您可以使用 Visual Command-Line 介面或直接在 NuGet Package Manager 中搜尋。

指令行安裝:

Install-Package IronPdf

另外,您也可以在 NuGet 套件管理員中搜尋"IronPDF"並進行安裝。

QuestPDF 新增頁碼到 PDF 的替代方案 VS IronPDF (範例):圖 2

什麼是 QuestPDF?

QuestPDF 是專為 PDF 文件生成而設計的現代化 .NET 函式庫。 它著重於為開發人員提供一個靈活、有效率的工具,以便從 C# 建立 PDF。 QuestPDF 允許以直覺、流暢的方式,使用宣告式風格來設計文件。

QuestPDF 強調簡單、速度和效能,因此是產生動態報表和文件的最佳選擇。 該資料庫還支援先進的排版功能、自訂樣式以及易於使用的範本。

QuestPDF 功能

  • 易於使用的 API,用於建立複雜的 PDF 文件。
  • 支援彈性的排版與文件結構,可設定預設頁面、欄目等。
  • 允許使用類似 CSS 的屬性輕鬆設定元素的樣式。
  • 提供對圖片、預設文字樣式設定、表格、Barcode、圖表、列、行、多頁面類型等的支援。
  • 非常適合建立報告、發票和資料驅動的文件。

如需詳細資訊,請參閱 QuestPDF 文件

安裝 QuestPDF。

若要開始使用 QuestPDF,請透過 NuGet 指令行安裝:

Install-Package QuestPDF

或是透過 NuGet 套件管理員:

QuestPDF 新增頁碼到 PDF 的替代方案 VS IronPDF (範例):圖 3

這將在您的專案中加入使用 QuestPDF 產生 PDF 所需的函式庫。

使用 IronPDF 添加頁碼。

IronPDF 提供了一種簡單的方法,可將 頁碼 添加至 PDF。 以下程式碼示範如何做到這一點:

using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        // HTML content for the PDF
        var html = "<h1>Hello World!</h1><p>This document was generated using IronPDF</p>";

        // Set up the IronPDF renderer with header for page numbers
        ChromePdfRenderer renderer = new ChromePdfRenderer
        {
            RenderingOptions = 
            {
                HtmlHeader = new HtmlHeaderFooter
                {
                    HtmlFragment = "<center><i>{page} of {total-pages}</i></center>"
                }
            }
        };

        // Render the HTML as a PDF
        PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

        // Save the PDF to a file
        pdf.SaveAs("pageNumbers.pdf");
    }
}
using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        // HTML content for the PDF
        var html = "<h1>Hello World!</h1><p>This document was generated using IronPDF</p>";

        // Set up the IronPDF renderer with header for page numbers
        ChromePdfRenderer renderer = new ChromePdfRenderer
        {
            RenderingOptions = 
            {
                HtmlHeader = new HtmlHeaderFooter
                {
                    HtmlFragment = "<center><i>{page} of {total-pages}</i></center>"
                }
            }
        };

        // Render the HTML as a PDF
        PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

        // Save the PDF to a file
        pdf.SaveAs("pageNumbers.pdf");
    }
}
Imports IronPdf

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' HTML content for the PDF
		Dim html = "<h1>Hello World!</h1><p>This document was generated using IronPDF</p>"

		' Set up the IronPDF renderer with header for page numbers
		Dim renderer As New ChromePdfRenderer With {
			.RenderingOptions = {
				HtmlHeader = New HtmlHeaderFooter With {.HtmlFragment = "<center><i>{page} of {total-pages}</i></center>"}
			}
		}

		' Render the HTML as a PDF
		Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)

		' Save the PDF to a file
		pdf.SaveAs("pageNumbers.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

輸出

QuestPDF 新增頁碼到 PDF 的替代方案 VS IronPDF (範例):圖 4

在這段程式碼中,我們為 PDF 文件建立了一個 HTML 標頭,其中 {page}{total-pages} 分別代表目前頁碼和總頁數的動態佔位符。 RenderHtmlAsPdf 方法將 HTML 轉換為 PDF。 此功能可根據文件長度動態調整頁面。

如何使用 QuestPDF 添加頁碼。

在 QuestPDF 中,可以用類似的方式添加頁碼。 以下是使用 QuestPDF 新增頁碼的程式碼:

using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

class Program
{
    static void Main(string[] args)
    {
        // Set the license type for QuestPDF
        QuestPDF.Settings.License = LicenseType.Community;

        // Create a PDF document using the QuestPDF fluent API
        var document = Document.Create(container =>
        {
            // Define a page with content and a header with page numbers
            container.Page(page =>
            {
                page.Content().Text("Hello, QuestPDF!");

                // Add a centered header with page number and total pages
                page.Header().AlignCenter().Text(text =>
                {
                    text.Span("Page ");
                    text.CurrentPageNumber();
                    text.Span(" of ");
                    text.TotalPages();
                });
            });
        });

        // Generate and save the PDF document
        document.GeneratePdf("QuestPdfOutput.pdf");
    }
}
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

class Program
{
    static void Main(string[] args)
    {
        // Set the license type for QuestPDF
        QuestPDF.Settings.License = LicenseType.Community;

        // Create a PDF document using the QuestPDF fluent API
        var document = Document.Create(container =>
        {
            // Define a page with content and a header with page numbers
            container.Page(page =>
            {
                page.Content().Text("Hello, QuestPDF!");

                // Add a centered header with page number and total pages
                page.Header().AlignCenter().Text(text =>
                {
                    text.Span("Page ");
                    text.CurrentPageNumber();
                    text.Span(" of ");
                    text.TotalPages();
                });
            });
        });

        // Generate and save the PDF document
        document.GeneratePdf("QuestPdfOutput.pdf");
    }
}
Imports QuestPDF.Fluent
Imports QuestPDF.Infrastructure

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Set the license type for QuestPDF
		QuestPDF.Settings.License = LicenseType.Community

		' Create a PDF document using the QuestPDF fluent API
		Dim document = Document.Create(Sub(container)
			' Define a page with content and a header with page numbers
			container.Page(Sub(page)
				page.Content().Text("Hello, QuestPDF!")

				' Add a centered header with page number and total pages
				page.Header().AlignCenter().Text(Sub(text)
					text.Span("Page ")
					text.CurrentPageNumber()
					text.Span(" of ")
					text.TotalPages()
				End Sub)
			End Sub)
		End Sub)

		' Generate and save the PDF document
		document.GeneratePdf("QuestPdfOutput.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

QuestPDF 新增頁碼到 PDF 的替代方案 VS IronPDF (範例):圖 5

此 QuestPDF 程式碼定義了一個簡單的文件,在標題中有一個頁碼。 CurrentPageNumber()TotalPages() 方法用於動態產生相對於每一頁的頁碼。

結論

QuestPDF 新增頁碼到 PDF 的替代方案 VS IronPDF (範例):圖 6

總而言之,IronPDF 和 QuestPDF 都提供了有效的解決方案,可以在 C# 中將 頁碼加到 PDF 中。 然而,IronPDF 提供了一種更精簡、更人性化的方法。 其靈活性和易用性使其成為需要添加頁碼或以最少的工作量處理現有 PDF 的開發人員的理想選擇。

IronPDF 可免費開發使用,讓開發人員可以在開發階段進行實驗,並將其整合至專案中,而無需支付任何費用。 一旦您準備好進行生產,商業授權可適用於這些授權選項。

透過選擇 IronPDF,開發人員可獲得可靠且功能豐富的工具,簡化 PDF 的建立與編輯,包括插入頁碼,並享有持續維護與更新的額外好處。

如需 IronPDF 免費版本和商業授權的詳細資訊,請造訪 IronPDF 官方網站

請注意QuestPDF 是其各自所有者的註冊商標。 本網站與 QuestPDF 無任何關聯、背書或贊助。 所有產品名稱、標誌和品牌均為其各自擁有者的財產。 比較僅供參考,反映了撰寫時的公開信息。

常見問題解答

如何使用 C# 為 PDF 文件添加頁碼?

您可以通過創建帶有佔位符如 {page}{total-pages} 的 HTML 頁眉或頁腳來使用 IronPDF 添加頁碼。當使用 RenderHtmlAsPdf 方法時,這些佔位符會動態更新以反映當前頁面和頁面總數。

IronPDF 和 QuestPDF 在 PDF 交互中的主要區別是什麼?

IronPDF 功能豐富,利用基於 Chromium 的引擎,非常適合需要精確佈局控制的 web 開發者。它支持將 HTML、CSS 和 JavaScript 轉換為 PDF。QuestPDF 提供現代聲明式 API,專注於簡潔性和性能,適合於具有靈活佈局的動態報告。

如何在 .NET 項目中安裝 PDF 庫?

要在.NET專案中安裝像IronPDF這樣的PDF庫,請使用Visual Studio中的NuGet套件管理器。您可以使用命令行以Install-Package IronPDF安裝它,或在NuGet套件管理器介面中找到它。

IronPDF 為 web 開發者帶來了什麼優勢?

IronPDF 對於 web 開發者來說是有利的,因為它能夠將 HTML、CSS 和 JavaScript 轉換成 PDF,保持精確的佈局和樣式。它還支持添加自定義的頁眉、頁腳,以及合併和拆分 PDF 等高級文件操作。

IronPDF 可以免費使用嗎?

是的,IronPDF 可以在開發階段免費使用,允許開發者整合並測試其功能而無需費用。然而,商業用途需要購買商業許可。

在 C# 中使用 PDF 庫進行文檔管理有什麼好處?

在 C# 中使用像 IronPDF 這樣的 PDF 庫簡化了文檔管理,使輕鬆生成、操作和轉換 PDF 成為可能。它提供了工具來保持一致的文檔表現,並支持添加頁碼,自定義頁眉,以及合併文檔等進階功能。

我可以使用 IronPDF 自定義 PDF 的外觀嗎?

是的,IronPDF 允許通過運用 HTML 和 CSS 來自定義 PDF 的樣式。您可以創建自定義頁眉、頁腳和水印,確保 PDF 符合特定的設計要求。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

QuestPDF Logo

厭倦了昂貴的續費和過時的產品更新嗎?

QuestPDF 輕鬆轉換為我們的工程遷移支援和更優惠的價格。

IronPDF Logo

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我