產品比較 QuestPDF向PDF添加頁碼的替代品VS IronPDF(示例) Curtis Chau 更新日期:7月 28, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 強大的檔案格式(PDF)是一種普遍使用的檔案格式,確保各個平台和設備上的文件呈現一致。 其固定版面使其成為分享論文、合約、發票等的首選格式。 在企業界,PDF 文件在正式文件中不可或缺。 隨著對 PDF 生成功能和操作的需求增加,出現了多個函式庫,簡化了開發人員的處理過程。 In this article, we'll explore how to add page numbers to a PDF using QuestPDF in C#, while also comparing QuestPDF with IronPDF to help you decide which library fits your project needs. 什麼是 IronPDF? IronPDF 是一個功能豐富的函式庫,為 .NET 生態系統所打造,旨在高效地處理 PDF 的創建、操作和呈現任務。 它利用 基於 Chromium 的引擎,提供對 HTML、CSS 和 JavaScript 精確轉換為 PDF 文件的能力。 這使其成為 Web 開發人員的絕佳選擇,能夠直接將 HTML 內容轉換為 PDF 格式,同時保留原始版式和樣式。 使用 IronPDF,您可以輕鬆地將 PDF 功能整合到您的 .NET 應用程式中,包括創建自定義頁眉和頁腳、向 PDF 添加新頁面、嵌入圖像和表格,以及執行高級 PDF 操作如合併或拆分文檔。 該函式庫支持多種格式,並提供廣泛的自定義選項,使其非常適合從動態 Web 內容生成專業級 PDF。 IronPDF 的主要功能: 允許您直接從 C# 程式碼生成 PDF。 將網頁、HTML 和 JavaScript 轉換為高品質的 PDF。 Provides options for adding custom elements like headers, footers, and watermarks. 方便合併、分拆和編輯現有 PDF 文件。 可與包括 ASP.NET 和 MVC 框架在內的 .NET 應用無縫協作。 要深入了解 IronPDF 的功能和更多高級範例,請參考官方文件此處。 安裝 IronPDF 要將IronPDF添加到您的項目中,可使用Visual Studio中的NuGet程序包管理器。 您可以使用可視命令行界面,或直接在 NuGet 包管理器中搜索。 命令行安裝: Install-Package IronPdf 或者,您可以在 NuGet 包管理器中搜索 "IronPDF" 並安裝。 什麼是 QuestPDF? QuestPDF 是一個專為 PDF 文件生成而設計的現代 .NET 函式庫。 它專注於為開發人員提供靈活高效的工具,以從 C# 設計 PDF。 QuestPDF 允許使用宣告式風格進行文件設計,提供直觀流暢的方法。 QuestPDF 強調簡單性、速度和性能,是生成動態報告和文件的絕佳選擇。 該函式庫還支持高級版面特性、自定義樣式和易用的模板。 QuestPDF 功能 易於使用的 API 用於構建複雜的 PDF 文件。 支持靈活的佈局和文件結構化,可設置預設頁面、列項等。 允許使用類似 CSS 的屬性輕鬆設計元素。 支持圖像、預設文本樣式設置、表格、條碼、圖表、列、行、多頁類型等。 非常適合用於創建報告、發票和數據驅動的文件。 有關更多詳細資訊,請參考 QuestPDF 文件。 安裝 QuestPDF 要開始使用 QuestPDF,請通過 NuGet 命令行安裝: Install-Package QuestPDF 或者,通過 NuGet 包管理器: 這將為您的項目添加所需的函式庫,以便用 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 輸出 在此代碼中,我們為 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 代碼定義了一個簡單的文檔,其中在頁眉中顯示頁碼。 CurrentPageNumber() 和 TotalPages() 方法用於動態生成每頁的頁碼。 結論 總之,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 機器人,結合科技與創意的樂趣。 相關文章 發表日期 11月 13, 2025 C# HTML 與 PDF 開源版本比較 IronPDF 將開源 HTML 轉 PDF 庫與 IronPDF for C# 進行比較。探索哪種解決方案能為您的 .NET 專案提供最佳的 PDF 生成功能。 閱讀更多 發表日期 10月 27, 2025 哪個 ASP.NET Core PDF 庫具有最佳價值? 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多 發表日期 10月 27, 2025 如何使用 Aspose C# 和 IronPDF 創建 PDF 通過這份針對開發人員設計的分步指南,學習如何使用 Aspose C# 與 IronPDF 創建 PDF。 閱讀更多 PDFsharp從PDF中提取文本VS IronPDF(示例)QuestPDF PDF到圖像轉換VS IronPDF
發表日期 11月 13, 2025 C# HTML 與 PDF 開源版本比較 IronPDF 將開源 HTML 轉 PDF 庫與 IronPDF for C# 進行比較。探索哪種解決方案能為您的 .NET 專案提供最佳的 PDF 生成功能。 閱讀更多
發表日期 10月 27, 2025 哪個 ASP.NET Core PDF 庫具有最佳價值? 發現適用於 ASP.NET Core 應用程式的最佳 PDF 庫。比較 IronPDF 的 Chrome 引擎與 Aspose 和 Syncfusion 的替代方案。 閱讀更多
發表日期 10月 27, 2025 如何使用 Aspose C# 和 IronPDF 創建 PDF 通過這份針對開發人員設計的分步指南,學習如何使用 Aspose C# 與 IronPDF 創建 PDF。 閱讀更多