跳至頁尾內容
產品對比
IronPDF 與 SpirePDF 的比較

SpirePDF C# HTML 轉 PDF 教學與函式庫比較

將 HTML 轉換為 PDF 是許多 .NET 應用程式的關鍵要求,從產生發票和報告到建立文件和電子書。 在選擇 IronPDF 和 Spire.PDF 來滿足您的 HTML 轉 PDF 轉換需求時,了解它們的優勢、限制和實際性能至關重要。 這份全面的比較報告檢視了這兩個函式庫的功能,幫助您根據自己的 PDF 產生需求做出明智的選擇。

IronPDF 和 Spire.PDF 在 HTML 轉 PDF 轉換上有哪些主要差異?

IronPDF 是一個功能全面的 .NET PDF 庫,旨在處理各種與 PDF 相關的任務,包括轉換 PDF 文件、編輯 PDF、建立 PDF、讀取 PDF 文件等等。 它以易於整合到現有的 .NET 應用程式中、高效能以及對 HTML5、CSS3 和 JavaScript 等現代 Web 標準的支援而聞名。 IronPDF 以 Chrome 為基礎的渲染引擎可確保從 HTML 內容產生像素級完美的 PDF 檔案。

Spire.PDF for .NET 是另一個功能強大的 .NET PDF 程式庫,它提供了一套全面的 PDF 建立和操作功能。 它支援各種 PDF 功能,例如文字和圖像提取、PDF 表單填寫和數位簽名。 雖然其功能全面,但其 HTML 轉 PDF 功能也存在一些開發人員應該考慮的特定限制。

產品對比概覽
IronPDF 和 Spire.PDF 在 .NET PDF 處理上的功能比較
類別特徵/方面IronPDFSpire.PDF主要優勢
核心架構設計理念簡潔至上、直覺易用的API多類別方法,手動設定IronPDF:更快的開發速度
API複雜度RenderHtmlAsPdf()這樣的簡單方法需要採用多執行緒方法。IronPDF:代碼量減少 70%。
學習曲線通常需要1-2天。通常需要 1-2 週。IronPDF:更快的採用
平台支援跨平台原生支持,無需額外軟體包Linux/macOS 支援有限IronPDF:真正的跨平台
.NET 版本.NET 8、7、6、5,Core 3.1+,Framework 4.6.2+.NET Core 2.0+,.NET Framework 2.0+兩者:廣泛的框架支持
作業系統Windows、Linux、macOS、Docker 原生主要針對 Windows 系統IronPDF:更廣泛的作業系統支援
HTML 轉 PDF渲染引擎全鍍鉻V8發動機自訂 HTML 解析器IronPDF:瀏覽器保真度超過 98%
CSS3/HTML5 支持全面支持有限(僅限基本 CSS)IronPDF:現代網路標準
JavaScript 執行完全支援 JavaScript已計劃但尚未實施IronPDF:動態內容準備就緒
網頁字體Google Fonts,系統字體字體支援有限IronPDF:排版靈活性
渲染速度典型值 0.8–1.2 秒簡單 HTML 的耗時為 0.5–0.8 秒Spire:更快的基本 HTML
Security & Encryption加密等級AES-256,自訂處理程序AES-256 標準兩者:業界標準
API 的簡潔性單一SecuritySettings多種安全措施IronPDF:統一方法
內容操縱編輯方法真正的內容移除,一行API手動矩形疊加IronPDF:符合合規要求
水印基於 HTML/CSS 的完整樣式基於文字並可旋轉IronPDF:豐富的浮水印
文件轉換DOCX 轉 PDF內建DocxToPdfRenderer需要 Spire.Doc 函式庫IronPDF:無額外費用
績效指標記憶體使用情況150–200MB(Chrome 引擎)80–120MBSpire:更低的記憶體佔用
螺紋支援原生 async/await 優化需要 STA 線程IronPDF:現代非同步模式
開發者體驗程式碼範例100 多個可直接運作的樣品基本範例IronPDF:豐富的資源
錯誤訊息描述性強,可操作科技資訊IronPDF:更好的調試
Licensing & Pricing入門級Lite: $799 (1 dev, 1 project)Developer: $1,199/year (1 dev)IronPDF:永久許可
團隊許可證Plus: $1,199 (3 devs, 3 projects)網址:4,599 美元(10 位開發者)IronPDF:更好的團隊價值
套房選項Iron Suite: $1,498 (9 products)無套房選項IronPDF:超值
支援包含支持是的,我們提供 24/5 全天候工程支援。僅限論壇討論(付費支援另計)IronPDF:包含支持
支援管道電子郵件、聊天、電話、螢幕分享論壇、電子郵件(付費版)IronPDF:更多頻道
最適合用例現代 Web 應用程序,複雜的 HTML/CSS簡單的文檔,基本的佈局上下文相關
注意: Spire.PDF 提供基本的 PDF 功能,記憶體佔用量較低;而 IronPDF 則在 HTML 渲染和對現代 Web 標準的支援方面表現出色。請根據您更重視的是複雜的 HTML 渲染還是最低的資源佔用來選擇。

有關 IronPDF 的更多詳細信息,請訪問IronPDF.com

各庫的跨平台相容性如何比較?

IronPDF

IronPDF 的優勢在於其廣泛的跨平台相容性。 它支援 .NET 框架內的各種環境,確保在不同平台上無縫運作。 以下是IronPDF平台相容性的概述:

  • .NET 版本:

    • 完全使用 C#、VB.NET 和 F# 編寫並提供支持
    • .NET Core(8、7、6、5 和 3.1+)
    • .NET Standard (2.0+)
    • .NET Framework (4.6.2+)

-應用環境: IronPDF 可在各種應用環境中執行,例如 Windows、Linux、Mac、Docker、Azure 和 AWS。 -整合開發環境 (IDE):相容於 Microsoft Visual Studio 和 JetBrains Rider & ReSharper 等整合開發環境。 -作業系統和處理器:支援多種作業系統和處理器,包括 Windows、Mac、Linux、x64、x86 和 ARM。

有關 IronPDF 相容性的更多詳細信息,請訪問IronPDF 功能頁面

Spire.PDF

Spire.PDF 在 .NET 環境中得到全面支持,但雖然它可以在 Windows 作業系統中運行,但它不像 IronPDF 那樣對 Linux 和 macOS 提供原生支援。 在 macOS 或 Linux 上部署時,Spire.PDF 需要針對每個平台安裝不同的插件,這可能會使部署場景變得複雜。

  • .NET 支援:
    • .NET Framework 2.0+
    • .NET Core 2.0+
    • 使用 C# 編寫,並支援 VB.NET

-應用環境: Spire.PDF 可在各種應用環境中運行,例如 Windows 和 ASP.NET 應用程式。 它還可以支援 Windows Forms。

哪個函式庫提供更好的 HTML 轉 PDF 功能?

IronPDF 功能

  • PDF轉換: IronPDF可以將HTML轉換為PDF 。 IronPDF 完全支援現代網路標準,因此您可以放心,它將始終如一地從您的 HTML 內容中返回像素級完美的 PDF 文件。 IronPDF 也可以將其他格式的檔案(例如DOCX 、映像檔、RTF 等)轉換為 PDF 檔案。
  • PDF 產生:使用 IronPDF,您可以從 URL、ASPX 檔案或 HTML 字串產生 PDF。 -安全功能:使用 IronPDF 的安全功能,您可以隨時確保任何敏感 PDF 檔案都是安全的。 使用 IronPDF 加密您的 PDF 文件、設定密碼並設定 PDF 文件的權限。
  • PDF 編輯功能:使用 IronPDF,您可以輕鬆處理現有的 PDF 文件、編輯它們以及閱讀 PDF 文件。 IronPDF 提供編輯功能,例如新增頁首和頁尾、在 PDF 頁面上新增文字和影像、新增自訂浮水印、處理 PDF 表單以及分割或合併 PDF 檔案。 -整合:與 ASP.NET 和 MVC 應用程式無縫整合。
  • PDF版本支援:支援PDF版本1.2-1.7

如需查看 IronPDF 功能的完整列表,請造訪IronPDF 功能頁面。

Spire.PDF 功能

  • PDF 建立:從零開始或從現有文件建立 PDF。 -文字與影像擷取:使用 Spire.PDF 擷取 PDF 頁面和內容。
  • PDF 表單處理:填寫和管理 PDF 表單。
  • PDF 轉換:將 PDF 轉換為其他格式,如 HTML、RTF 和映像。 -頁面操作:在 PDF 中插入、刪除和重新排列頁面。
  • HTML 支援有限: HTML 轉 PDF 引擎對現代 CSS 和 JavaScript 的支援有限。 預設的基於 Qt 的插件不支援 CSS 分頁屬性或外部 CSS 檔案識別,JavaScript 執行是一項計劃中的功能,尚未完全實現。 可以使用可選的 ChromeHtmlConverter 來獲得更好的渲染效果。

Bootstrap 與現代 CSS 框架渲染

現代網頁開發非常依賴 Bootstrap 等 CSS 框架來實現快速 UI 開發和響應式設計。 PDF 生成庫必須準確地轉換這些框架,以保持專業的文件品質和設計一致性。

IronPDF:完全支援 Bootstrap 和 Tailwind

IronPDF 的 Chromium 引擎全面支援所有現代 CSS 框架:

  • Bootstrap 5:完全支援 Flexbox 和 CSS Grid,以及所有響應式元件
  • Bootstrap 4:完整的卡片佈局、導航系統和實用類
  • Tailwind CSS:所有實用性優先的類別和響應式修飾符 -基礎:完整的網格和組件系統 -現代 CSS3: Flexbox、Grid、自訂屬性、動畫和變換

真實案例證明: Bootstrap 首頁Bootstrap 範本能夠實現像素級精準轉換。

程式碼範例:使用 Bootstrap 建立團隊成員卡片

using IronPdf;

var renderer = new ChromePdfRenderer();

string bootstrapTeam = @"
<!DOCTYPE html>
<html>
<head>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
    <div class='container my-5'>
        <h1 class='text-center mb-5'>Our Team</h1>

        <div class='row row-cols-1 row-cols-md-3 g-4'>
            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>Jennifer Martinez</h5>
                        <p class='text-muted mb-3'>Chief Technology Officer</p>
                        <p class='card-text flex-grow-1'>Leading our technical vision and innovation strategy with over 15 years of experience in software architecture.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>David Chen</h5>
                        <p class='text-muted mb-3'>Head of Engineering</p>
                        <p class='card-text flex-grow-1'>Managing our engineering teams and ensuring product quality through rigorous testing and code review processes.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>Sarah Johnson</h5>
                        <p class='text-muted mb-3'>Product Manager</p>
                        <p class='card-text flex-grow-1'>Driving product strategy and customer satisfaction through data-driven decisions and user research.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='text-center mt-5'>
            <h3>Join Our Team</h3>
            <p class='text-muted mb-3'>We're always looking for talented individuals to join our growing team.</p>
            <a href='#' class='btn btn-primary btn-lg'>View Open Positions</a>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(bootstrapTeam);
pdf.SaveAs("team-members.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

string bootstrapTeam = @"
<!DOCTYPE html>
<html>
<head>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
    <div class='container my-5'>
        <h1 class='text-center mb-5'>Our Team</h1>

        <div class='row row-cols-1 row-cols-md-3 g-4'>
            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>Jennifer Martinez</h5>
                        <p class='text-muted mb-3'>Chief Technology Officer</p>
                        <p class='card-text flex-grow-1'>Leading our technical vision and innovation strategy with over 15 years of experience in software architecture.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>David Chen</h5>
                        <p class='text-muted mb-3'>Head of Engineering</p>
                        <p class='card-text flex-grow-1'>Managing our engineering teams and ensuring product quality through rigorous testing and code review processes.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col'>
                <div class='card h-100 shadow-sm text-center'>
                    <div class='card-body d-flex flex-column'>
                        <img src='https://via.placeholder.com/150' class='rounded-circle mx-auto mb-3' alt='Team member' style='width: 150px; height: 150px; object-fit: cover;'>
                        <h5 class='card-title'>Sarah Johnson</h5>
                        <p class='text-muted mb-3'>Product Manager</p>
                        <p class='card-text flex-grow-1'>Driving product strategy and customer satisfaction through data-driven decisions and user research.</p>
                        <div class='d-flex justify-content-center gap-2 mt-auto'>
                            <a href='#' class='btn btn-sm btn-outline-primary'>LinkedIn</a>
                            <a href='#' class='btn btn-sm btn-outline-secondary'>Email</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='text-center mt-5'>
            <h3>Join Our Team</h3>
            <p class='text-muted mb-3'>We're always looking for talented individuals to join our growing team.</p>
            <a href='#' class='btn btn-primary btn-lg'>View Open Positions</a>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(bootstrapTeam);
pdf.SaveAs("team-members.pdf");
$vbLabelText   $csharpLabel

輸出:一個專業的團隊頁面,採用 Bootstrap 的卡片網格、flexbox 對齊方式、響應式圖像和按鈕元件——所有內容都能在 PDF 中準確呈現。

Spire.PDF:HTML 和現代框架支援有限

Spire.PDF 的 HTML 轉 PDF 引擎對於現代 CSS 框架有許多局限性,這一點在其官方文件中已有說明:

  • CSS 支援有限:僅支援基本 CSS,不具備全面的 CSS3 功能 -不支援 Flexbox: Bootstrap 4/5 嚴重依賴 Flexbox,而 Flexbox 不支援。 -不支援 CSS Grid:使用 CSS Grid 的現代佈局系統將無法正確渲染。
  • JavaScript 的限制:與現代瀏覽器相比,JavaScript 執行效率極低。
  • Bootstrap 版本上限:僅支援較舊的基於表格的 Bootstrap 版本,且運作穩定可靠。 -複雜佈局失敗:現代響應式設計需要大量的變通方法

開發者報告的 Spire.PDF HTML 轉換問題: Bootstrap導覽列渲染時出現版面問題 使用 Flexbox 佈局的卡片元件無法正確對齊。

  • PDF 輸出中會忽略響應式網格斷點
  • 現代 CSS 特性需要手動重寫 CSS 程式碼或使用回退方案

開發影響:使用 Bootstrap 4+ 或現代 CSS 框架的應用程式在使用 Spire.PDF 時面臨重大挑戰。 開發團隊必須:

  1. 維護一套專門用於產生 PDF 的獨立簡化 CSS(雙重維護)
  2. 降級到 Bootstrap 3 或完全放棄框架(限制了現代功能)
  3. 對每個組件進行全面測試和手動修復(耗時且易碎)

對於需要現代 CSS 框架支援的專案而言,Spire.PDF 的 HTML 渲染限制使其不適用,除非投入大量額外開發精力並承擔持續維護的負擔。

有關 Bootstrap 相容性的詳細信息,請參閱Bootstrap 和 Flexbox CSS 指南

常見 PDF 任務的程式碼範例有何異同?

為了說明 IronPDF 和 Spire.PDF for .NET 的功能,我們將透過程式碼範例比較它們對幾個關鍵 PDF 功能的實現,讓您了解這些功能如何幫助您的 PDF 專案。

將 HTML 轉換為 PDF

IronPDF 範例:

using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

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

// Create a PDF from an HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");

// Advanced Example with HTML Assets
// Load external HTML assets: images, CSS, and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

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

// Create a PDF from an HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");

// Advanced Example with HTML Assets
// Load external HTML assets: images, CSS, and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
$vbLabelText   $csharpLabel

IronPDF 中的ChromePdfRenderer類別利用完整的 Chrome 瀏覽器引擎來渲染 HTML 內容。 這意味著 CSS3 動畫、JavaScript 執行和現代網頁字體都會像在 Chrome 中一樣呈現。 RenderHtmlAsPdf()方法接受 HTML 字串和用於載入外部資源的可選基本路徑,從而可以輕鬆轉換簡單和複雜的 HTML 文件。 渲染器支援進階渲染選項,包括自訂紙張尺寸、邊距和 JavaScript 延遲設定。

Spire.PDF 範例:

using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;

namespace ConvertHtmlStringToPdfWithoutPlugin
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Create a PdfPageSettings object
            PdfPageSettings setting = new PdfPageSettings();

            // Set page size and margins through the object
            setting.Size = new SizeF(1000, 1000);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

            // Create a PdfHtmlLayoutFormat object
            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            // Set IsWaiting property to true
            htmlLayoutFormat.IsWaiting = true;

            // Read HTML string from a .html file
            string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");

            // Load HTML from HTML string using LoadFromHTML method
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            // Save to a PDF file
            doc.SaveToFile("HtmlStringToPdf.pdf");
        }
    }
}
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;

namespace ConvertHtmlStringToPdfWithoutPlugin
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Create a PdfPageSettings object
            PdfPageSettings setting = new PdfPageSettings();

            // Set page size and margins through the object
            setting.Size = new SizeF(1000, 1000);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

            // Create a PdfHtmlLayoutFormat object
            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            // Set IsWaiting property to true
            htmlLayoutFormat.IsWaiting = true;

            // Read HTML string from a .html file
            string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");

            // Load HTML from HTML string using LoadFromHTML method
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            // Save to a PDF file
            doc.SaveToFile("HtmlStringToPdf.pdf");
        }
    }
}
$vbLabelText   $csharpLabel

Spire.PDF 的 HTML 到 PDF 轉換需要建立多個對象,包括PdfDocumentPdfPageSettingsPdfHtmlLayoutFormat 。 轉換必須在單執行緒單元 (STA) 執行緒中執行,這增加了實現的複雜性。 使用者反映"Spire 產生的 PDF 檔案其實只是一張圖片。 部分 CSS 程式碼甚至不正確,例如忽略粗體字",這表明 CSS 渲染保真度有其限制。

IronPDF 使用 Chrome 的渲染引擎進行高保真 HTML 到 PDF 的轉換,由於其支援現代 Web 標準,因此能夠確保準確地呈現 Web 內容。 Spire.PDF 也提供強大的 HTML 轉 PDF 功能,但其渲染精度可能不如 IronPDF,而且需要更長、更手動的操作。

如何加密PDF文件?

IronPDF 範例:

using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from HTML
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
$vbLabelText   $csharpLabel

IronPDF 的SecuritySettings類別提供了一個全面的 API 來管理 PDF 安全性。 您可以使用布林屬性控制單一權限,設定不同等級的列印權限,並將密碼與其他安全設定分開管理。 API 設計遵循 .NET 約定,採用強型別枚舉,如PdfPrintSecurity 。 請參閱文檔,以了解有關PDF 權限和密碼的更多資訊。

Spire.PDF 範例:

using Spire.Pdf;
using Spire.Pdf.Security;

// Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

// Load a sample PDF file
pdf.LoadFromFile(@"E:\Files\sample.pdf");

// Encrypt the PDF file with a password
pdf.Security.Encrypt("open", "permission", PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent, PdfEncryptionKeySize.Key128Bit);

// Save the result file
pdf.SaveToFile("Encrypt.pdf", FileFormat.PDF);
using Spire.Pdf;
using Spire.Pdf.Security;

// Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

// Load a sample PDF file
pdf.LoadFromFile(@"E:\Files\sample.pdf");

// Encrypt the PDF file with a password
pdf.Security.Encrypt("open", "permission", PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent, PdfEncryptionKeySize.Key128Bit);

// Save the result file
pdf.SaveToFile("Encrypt.pdf", FileFormat.PDF);
$vbLabelText   $csharpLabel

Spire.PDF 的加密方法使用Security.Encrypt()方法,並帶有用於權限的位元標誌。 雖然這種方法更加緊湊,但需要了解位元運算,並且與 IronPDF 的單獨權限屬性相比,提供的控製粒度較窄。

這兩個庫都提供了易於使用的方法來加密 PDF 並設定加密 PDF 文件的可讀性。 IronPDF 提供了一個簡單直接的方法,同時也能讓您完全掌控 PDF 的安全設定。 Spire.PDF 的處理過程稍短一些,但仍包含設定權限的額外選項。

有哪些選項可以用來編輯 PDF 內容?

IronPDF 範例:

using IronPdf;

// Load the PDF document
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");

// Save the redacted document
pdf.SaveAs("redacted.pdf");
using IronPdf;

// Load the PDF document
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");

// Save the redacted document
pdf.SaveAs("redacted.pdf");
$vbLabelText   $csharpLabel

IronPDF 提供專用的編輯 API ,可執行真正的內容刪除,而不僅僅是視覺遮蔽。 RedactTextOnAllPages()方法會搜尋並永久刪除指定的文本,確保符合資料保護法規。 其他方法允許對特定頁面或區域進行編輯。

Spire.PDF 範例:透過矩形疊加進行內容編輯:

雖然 Spire.PDF 沒有專門的編輯工具,但仍可以使用手動方式編輯內容,如下所示:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Specify the input PDF file path
string inputPdfFilePath = "path/to/your/input.pdf";

// Specify the output redacted PDF file path
string outputPdfFilePath = "path/to/your/redacted_output.pdf";

// Create a new PdfDocument object
PdfDocument pdfDocument = new PdfDocument();

// Load the existing PDF document
pdfDocument.LoadFromFile(inputPdfFilePath);

// Redact content on each page
foreach (PdfPageBase page in pdfDocument.Pages)
{
    // Define the area to redact (e.g., coordinates and size of the rectangle)
    RectangleF redactArea = new RectangleF(100, 100, 200, 50); // Example coordinates and size

    // Apply redaction
    page.Canvas.DrawRectangle(new PdfSolidBrush(Color.Black), redactArea);
}

// Save the redacted PDF document
pdfDocument.SaveToFile(outputPdfFilePath);
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Specify the input PDF file path
string inputPdfFilePath = "path/to/your/input.pdf";

// Specify the output redacted PDF file path
string outputPdfFilePath = "path/to/your/redacted_output.pdf";

// Create a new PdfDocument object
PdfDocument pdfDocument = new PdfDocument();

// Load the existing PDF document
pdfDocument.LoadFromFile(inputPdfFilePath);

// Redact content on each page
foreach (PdfPageBase page in pdfDocument.Pages)
{
    // Define the area to redact (e.g., coordinates and size of the rectangle)
    RectangleF redactArea = new RectangleF(100, 100, 200, 50); // Example coordinates and size

    // Apply redaction
    page.Canvas.DrawRectangle(new PdfSolidBrush(Color.Black), redactArea);
}

// Save the redacted PDF document
pdfDocument.SaveToFile(outputPdfFilePath);
$vbLabelText   $csharpLabel

這種手動方法需要計算每個編輯區域的精確座標,並且只能提供視覺遮罩,而不能真正刪除內容。 仍然可以透過 PDF 編輯工具提取出底層文字。

IronPDF 憑藉其強大而又簡單易用的編輯工具,簡化了編輯過程。 Spire.PDF 由於缺乏內建的編輯工具,需要更多的手動處理才能進行編輯,這可能會導致工作流程效率降低。

如何簽署PDF文件?

IronPDF 範例:

using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

// Instantiate the renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PdfSignature with certificate
var sig = new PdfSignature(cert);

// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

// Instantiate the renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PdfSignature with certificate
var sig = new PdfSignature(cert);

// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
$vbLabelText   $csharpLabel

IronPDF 的數位簽章實作遵循 .NET 憑證處理模式。 PdfSignature類別接受標準的 X509Certificate2 對象,並在內部處理 PDF 簽章的複雜度。 您也可以新增視覺簽名外觀並配置簽名欄位。

Spire.PDF 範例:

using Spire.Pdf;
using Spire.Pdf.Security;
using System.Drawing;

// Create a PdfDocument object
PdfDocument doc = new PdfDocument();

// Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

// Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

// Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54 , 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;

// Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

// Set various details about the signature
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

// Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");

// Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

// Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

// Save to file
doc.SaveToFile("VisiableSignature.pdf");
using Spire.Pdf;
using Spire.Pdf.Security;
using System.Drawing;

// Create a PdfDocument object
PdfDocument doc = new PdfDocument();

// Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

// Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

// Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54 , 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;

// Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

// Set various details about the signature
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

// Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");

// Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

// Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

// Save to file
doc.SaveToFile("VisiableSignature.pdf");
$vbLabelText   $csharpLabel

Spire.PDF 提供了對簽名外觀的全面控制,但需要編寫更多的程式碼。 您必須手動設定每個標籤,精確定位簽名,並分別配置視覺元素。

數位簽章 PDF 在各種情況下都很有用,從用於驗證 PDF 文件到簡單地簽署新項目。 IronPDF 提供了一種簡單直接的方式來添加數位簽名,從而可以輕鬆實現簽名流程的自動化。 Spire.PDF 也支援 PDF 的數位簽章; 然而,這個過程可能需要更多人工操作,並且需要投入更多精力才能實施。

有哪些方法可以為PDF文件加上浮水印?

IronPDF 範例:

using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
$vbLabelText   $csharpLabel

IronPDF 的浮水印功能接受 HTML 內容,讓您可以使用 CSS 進行樣式設定。 ApplyWatermark()方法提供了旋轉角度和對齊方式的參數,使得精確定位浮水印變得容易。 了解更多關於自訂浮水印和進階樣式選項的資訊。

Spire.PDF 範例:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

// Load a sample PDF document
pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

// Create a PdfTrueTypeFont object
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 50f), true);

// Set the watermark text
string text = "CONFIDENTIAL";

// Measure the text size
SizeF textSize = font.MeasureString(text);

// Calculate the values of two offset variables,
// which will be used to calculate the translation amount of the coordinate system
float offset1 = (float)(textSize.Width * System.Math.Sqrt(2) / 4);
float offset2 = (float)(textSize.Height * System.Math.Sqrt(2) / 4);

// Traverse all the pages in the document
foreach (PdfPageBase page in pdf.Pages)
{
    // Set the page transparency
    page.Canvas.SetTransparency(0.8f);

    // Translate the coordinate system by specified coordinates
    page.Canvas.TranslateTransform(page.Canvas.Size.Width / 2 - offset1 - offset2, page.Canvas.Size.Height / 2 + offset1 - offset2);

    // Rotate the coordinate system 45 degrees counterclockwise
    page.Canvas.RotateTransform(-45);

    // Draw watermark text on the page
    page.Canvas.DrawString(text, font, PdfBrushes.DarkGray, 0, 0);
}

// Save the changes to another file
pdf.SaveToFile("TextWatermark.pdf");
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Create a PdfDocument object
PdfDocument pdf = new PdfDocument();

// Load a sample PDF document
pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

// Create a PdfTrueTypeFont object
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 50f), true);

// Set the watermark text
string text = "CONFIDENTIAL";

// Measure the text size
SizeF textSize = font.MeasureString(text);

// Calculate the values of two offset variables,
// which will be used to calculate the translation amount of the coordinate system
float offset1 = (float)(textSize.Width * System.Math.Sqrt(2) / 4);
float offset2 = (float)(textSize.Height * System.Math.Sqrt(2) / 4);

// Traverse all the pages in the document
foreach (PdfPageBase page in pdf.Pages)
{
    // Set the page transparency
    page.Canvas.SetTransparency(0.8f);

    // Translate the coordinate system by specified coordinates
    page.Canvas.TranslateTransform(page.Canvas.Size.Width / 2 - offset1 - offset2, page.Canvas.Size.Height / 2 + offset1 - offset2);

    // Rotate the coordinate system 45 degrees counterclockwise
    page.Canvas.RotateTransform(-45);

    // Draw watermark text on the page
    page.Canvas.DrawString(text, font, PdfBrushes.DarkGray, 0, 0);
}

// Save the changes to another file
pdf.SaveToFile("TextWatermark.pdf");
$vbLabelText   $csharpLabel

Spire.PDF 的浮水印功能需要使用座標系變換手動計算定位和旋轉。 雖然這種方法可以實現精細控制,但需要理解圖形程式設計概念。

IronPDF 提供了一種簡單的方法來添加文字浮水印,同時讓您可以完全控制浮水印的位置和設計。 IronPDF 使用 HTML 和 CSS,如果您有這些語言的經驗,這將使操作過程更加輕鬆。 Spire.PDF 的方法耗時更長,需要更多手動操作,但仍然提供了一個強大的水印工具,可以完全控制設計和位置。

如何在PDF上新增圖片和文字?

IronPDF 範例:

using IronPdf;
using IronPdf.Editing;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
using IronPdf;
using IronPdf.Editing;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
$vbLabelText   $csharpLabel

IronPDF 的圖章 API 為不同UseGoogleFont TextStamper直接支援 Google Fonts,而ImageStamper可以從 URL 或本機檔案載入圖片。 這兩個沖壓機具有共同的對齊屬性,以實現一致的定位。 探索更多印章選項,包括 HTML 印章和條碼整合。

Spire.PDF(文字加蓋範例):

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Assumes a PdfDocument is already loaded as `doc` object
PdfPageBase page = doc.Pages[0];
PdfGraphicsState state = page.Canvas.Save();

// Define font and brushes for different effects
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

// Apply transformations and draw strings with shadow and effect
page.Canvas.TranslateTransform(20, 200);
page.Canvas.ScaleTransform(1f, 0.6f);
page.Canvas.SkewTransform(-10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);
page.Canvas.SkewTransform(10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);
page.Canvas.ScaleTransform(1f, -1f);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);

// Restore graphics to previous state
page.Canvas.Restore(state);
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

// Assumes a PdfDocument is already loaded as `doc` object
PdfPageBase page = doc.Pages[0];
PdfGraphicsState state = page.Canvas.Save();

// Define font and brushes for different effects
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

// Apply transformations and draw strings with shadow and effect
page.Canvas.TranslateTransform(20, 200);
page.Canvas.ScaleTransform(1f, 0.6f);
page.Canvas.SkewTransform(-10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);
page.Canvas.SkewTransform(10, 0);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);
page.Canvas.ScaleTransform(1f, -1f);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);

// Restore graphics to previous state
page.Canvas.Restore(state);
$vbLabelText   $csharpLabel

Spire.PDF 需要直接操作畫布,並手動變換每個效果。 創建複雜的印章需要了解圖形狀態管理和座標變換。

IronPDF 的文字和圖像加蓋工具是一款功能強大、易於使用的加蓋工具,其應用加蓋內容的方式與 HTML 和 CSS 類似。 雖然 Spire.PDF 也提供了一個基本的文字蓋章工具,但要將蓋章文字應用到 PDF 檔案中則需要更多步驟。

哪個函式庫在 DOCX 轉 PDF 方面表現較好?

IronPDF 範例:

using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
$vbLabelText   $csharpLabel

IronPDF 包含一個專用的DocxToPdfRenderer類,可原生處理 DOCX 轉換。 該 API 與 IronPDF 中的其他渲染類別一致,基本轉換只需要兩行程式碼。 頁面設定和格式的進階選項可透過渲染器的屬性取得。 了解更多關於DOCX轉PDF轉換功能的資訊。

使用 Spire.Doc 將 DOCX 轉換為 PDF:

Spire.PDF 本身無法將 DOCX 轉換為 PDF; 不過,可以使用 Spire.Doc 函式庫來處理這種轉換,然後可以使用 Spire.PDF 來處理產生的 PDF。

using Spire.Doc;

// Create a Document object
Document doc = new Document();

// Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.docx");

// Save the document to PDF
doc.SaveToFile("ToPDF.pdf", FileFormat.PDF);

// Dispose of resources
doc.Dispose();
using Spire.Doc;

// Create a Document object
Document doc = new Document();

// Load a Word document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.docx");

// Save the document to PDF
doc.SaveToFile("ToPDF.pdf", FileFormat.PDF);

// Dispose of resources
doc.Dispose();
$vbLabelText   $csharpLabel

這種方法需要購買和管理額外的庫(Spire.Doc),這會增加成本和複雜性。

IronPDF 提供直接 DOCX 到 PDF 轉換的內建支持,這意味著您無需額外的庫來處理此任務即可節省時間。 另一方面,Spire.PDF 無法直接處理 DOCX 到 PDF 的轉換,需要 Spire.Doc 函式庫將 DOCX 檔案轉換為 PDF。

績效指標揭示了什麼?

根據測試和使用者回饋,以下是這些庫在實際使用中的比較:

渲染效能

對於基本佈局,Spire.PDF 針對靜態表格或基本樣式文字等簡單內容進行了最佳化,因此在這些使用場景中速度快、效率高。 但是,當處理包含現代 CSS3 功能、JavaScript 或響應式佈局的複雜 HTML 時,IronPDF 基於 Chrome 的引擎可以提供更準確的結果,但代價是渲染時間略長。

記憶體使用情況

由於 Spire.PDF 的渲染引擎較為簡單,因此其記憶體佔用通常比 IronPDF 低(Spire.PDF 佔用 80-120MB,IronPDF 佔用 150-200MB)。然而,這也導致渲染精度和功能支援有所降低。 對於記憶體至關重要且 HTML 複雜度極低的應用場景,Spire.PDF 可能具有優勢。

線程和異步支持

IronPDF 提供原生 async/await 支持,例如RenderHtmlAsPdfAsync()方法,使其適用於現代 .NET 應用程式。 Spire.PDF 需要使用 STA 執行緒進行手動執行緒管理,這增加了多執行緒應用程式的複雜性。

定價和授權模式有何異同?

IronPDF定價和許可

IronPDF提供不同等級的許可證和附加功能供用戶購買。 開發者還可以購買Iron Suite ,以兩款產品的價格獲得 Iron Software 的所有產品。 如果您尚未準備好購買許可證,IronPDF 提供 30 天的免費試用期

定價(截至 2025 年):

-永久許可證:根據您的團隊規模、專案需求和地點數量,提供一系列永久許可證。 每種許可證類型都包含電子郵件支援服務。

  • Lite 許可證:此許可證價格為$799 ,支援一名開發者、一個地點和一個專案。
  • Plus 授權:支援三個開發者、三個地點和三個項目,這是比精簡版授權更進一步的版本,價格為$1,199 。 Plus 許可證除了提供基本的電子郵件支援外,還提供聊天支援和電話支援。 -專業許可證:此許可證適用於較大的團隊,支援十名開發人員、十個地點和十個項目,價格為$2,399 。 它提供與前幾個層級相同的聯絡支援管道,但也提供螢幕共享支援。 -免版稅再分發: IronPDF 的授權協議還提供免版稅再分發保障,需額外支付$2,399費用。 -不間斷的產品支援: IronPDF 提供持續的產品更新、安全功能升級以及來自其工程團隊的支持,價格為每年 999 美元,或一次性購買 1,999 美元即可獲得 5 年的保障。
  • Iron Suite:只需$1,498 ,即可存取所有 Iron Software 產品,包括 IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint 和 IronWebScraper。

IronPDF 定價表 IronPDF 提供靈活的許可選項,包括永久許可和全面的技術支援。

Spire.PDF 定價和許可

Spire.PDF 依據您的需求提供多種授權方案。

-免費版本: Spire.PDF 提供免費版本,但僅限 10 頁 PDF 檔案; 除此之外,您還需要購買付費許可證。 -開發者訂閱:根據您需要的支援類型,每年定價為 999 美元或 1199 美元,此選項適用於需要建立 PDF 相關功能但不需要 OEM 分發權的開發者。 -開發者 OEM 訂閱:每年費用約為 2,549 美元至 4,248 美元,具體取決於您需要的支援量,包括免費升級、高級支援以及將應用程式分發給最終用戶的能力。 -小型企業網站:根據您需要的支持,價格為 4,599 美元或 7,598 美元,此許可等級支援最多 10 個開發人員在最多 10 個地點工作,1 年的更新,以及免費的線上技術資源。 -網站 OEM 訂閱:每年費用為 13,088 美元至 16,687 美元,具體取決於您需要的支援類型,面向需要在多個位置部署應用程式的大型企業。

哪個圖書館提供更好的文件和支援?

IronPDF

IronPDF 在提供全面的文件和支援方面表現出色:

-全面的文件:涵蓋所有功能的詳盡且用戶友好的文件

  • 24/5 支援:提供線上工程師支援。 -影片教學: YouTube 上提供逐步影片指南。 -社群論壇:活躍的社群成員可獲得更多支援。 -定期更新:每月進行產品更新,以確保最新功能和安全性修補程式。
  • PDF API 參考:提供API 參考,以便您充分利用我們工具的功能。

有關更多信息,請查看 IronPDF 的詳細文檔,並訪問Iron Software YouTube 頻道

Spire.PDF .NET 文件和支持

-論壇: Spire.PDF 有一個論壇,使用者可以在這裡互相交流,分享使用 Spire.PDF 的技巧、用法和遇到的問題。 -程式碼範例: Spire.PDF 在其網站上提供程式碼範例,展示如何在各種使用情境中使用該產品。 -新聞簡報: Spire.PDF 提供開發者新聞簡報,用於發布更新公告和其他重要資訊。 -支援:主要透過論壇提供支持,根據許可版本,還可以付費獲得電子郵件/電話支持,但需額外付費。

開發者的常見經驗和回饋有哪些?

基於社群回饋和實際使用情況:

IronPDF 回饋

開發人員一直稱讚 IronPDF 提供了"更全面、更精確的原始 HTML 頁面表示"。 該程式庫能夠處理複雜的 CSS3 佈局、JavaScript 密集頁面和現代 Web 框架,因此成為需要高保真 PDF 生成的應用程式的首選。

常見的優點包括:

  • 直覺的 API 設計,可縮短開發時間
  • 出色的渲染質量,與瀏覽器輸出完全匹配
  • 包含實用範例的全面文檔
  • 快速回應的技術支持

Spire.PDF 回饋

社群回饋表明,"Spire 產生的 PDF 檔案實際上只是一張圖片。 部分 CSS 程式碼甚至不正確,例如忽略粗體字體"。 此外,官方支援回應稱,JavaScript 支援仍然是一項計劃中的功能,"由於難度太大,短期內無法完成"。

常見問題包括:

  • 對 CSS3 和現代 Web 標準的支援有限
  • 缺乏 JavaScript 執行能力
  • HTML轉換的複雜線程要求
  • 某些功能需要額外的函式庫

何時該選擇哪座圖書館?

選擇 IronPDF 的情況:

  • 您的 HTML 程式碼包含現代 CSS3、JavaScript 或響應式設計 你需要像素級精確渲染,與瀏覽器輸出完全匹配
  • 需要跨平台部署(Linux、macOS、Docker) 您希望您的許可證包含全面的支援服務。 您需要內建功能,例如無需額外庫的 DOCX 轉換。 您的團隊重視使用最少的程式碼實現快速開發。

選擇 Spire.PDF 時:

  • 您的PDF檔案僅包含基本的HTML程式碼和簡單的樣式。 記憶體使用情況是一個關鍵限制因素。 您主要在 Windows 環境中工作。 您的 HTML 程式碼不需要執行 JavaScript。
  • 您目前已在使用其他 Spire 產品。

結論

總之,IronPDF 和 Spire.PDF for .NET 都是在 .NET 應用程式中處理 PDF 文件的強大的工具。 IronPDF 在易用性、跨平台相容性和對現代網路標準的支援方面表現出色,如果您希望在處理 PDF 文件時提升效率,IronPDF 將是您的首選。 Spire.PDF 提供了一套全面的功能,但對於複雜的任務可能需要付出更多努力,並且缺乏現代 Web 應用程式所要求的渲染精度。

對於使用現代 Web 技術、需要精確的 HTML 到 PDF 轉換或需要可靠的跨平台支援的開發人員來說,IronPDF 提供了一個更完整的解決方案。 它基於 Chrome 的渲染引擎、直覺的 API 和全面的支持,使其特別適合企業應用程式和複雜的文件生成場景。

您可以嘗試30 天免費試用,以了解其可用功能。

請注意Spire.PDF 是其各自所有者的註冊商標。 本網站與 Spire.PDF 無任何關聯,亦未獲得其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 文中比較僅供參考,反映的是撰寫本文時可公開取得的資訊。

常見問題解答

如何在C#中將HTML轉換為PDF?

您可以使用 IronPDF 的RenderHtmlAsPdf方法將 HTML 字串轉換為 PDF。您也可以使用RenderHtmlFileAsPdf將 HTML 檔案轉換為 PDF。

IronPDF是否支援在HTML轉PDF過程中執行JavaScript?

是的,IronPDF 支援完整的 JavaScript 執行,因此非常適合將動態內容或依賴 JavaScript 的佈局轉換為 PDF。

IronPDF支援哪些平台進行PDF轉換?

IronPDF 提供跨多個平台的原生支持,包括 Windows、Linux、macOS、Docker 以及 Azure 和 AWS 等雲端服務。

IronPDF 的記憶體使用情況與 Spire.PDF 相比如何?

IronPDF 使用的記憶體略多,通常在 150-200MB 之間,而 Spire.PDF 的記憶體使用量為 80-120MB,但它提供了更好的渲染質量,並支援現代的 async/await 模式。

IronPDF可以直接將DOCX檔案轉換為PDF嗎?

是的,IronPDF 透過其DocxToPdfRenderer類別內建了 DOCX 到 PDF 的轉換功能,無需額外的程式庫。

IronPDF有哪些授權許可選項?

IronPDF 為單一開發者提供永久授權,起價為 749 美元,包含所有功能和支援。此外,它還提供包含 9 款產品的 Iron Suite 套裝,售價 1,498 美元。

IronPDF提供哪些類型的支援?

IronPDF 透過電子郵件、聊天、電話和螢幕分享為所有許可證提供 24/5 全天候工程支持,確保提供全面的幫助。

如何使用 IronPDF 確保 PDF 的安全性和加密性?

IronPDF 透過其SecuritySettings類別支援 AES-256 加密和密碼保護,從而可以對 PDF 權限進行精細控制。

IronPDF 適合渲染使用現代 CSS 的複雜網頁?

是的,IronPDF 使用完整的 Chrome 渲染引擎,支援 CSS3、flexbox、網格佈局、Web 字體和 JavaScript,使其非常適合複雜的網頁。

IronPDF免費版有哪些限制?

IronPDF 提供 30 天全功能免費試用,沒有頁數限制,讓您在購買前有充足的機會測試其所有功能。

IronPDF 如何確保高品質的 HTML 渲染?

IronPDF 提供像素級完美渲染,與 Chrome 瀏覽器輸出相匹配,確保對原始 HTML 內容的高保真度和精確還原。

Jacob Mellor,Team Iron 首席技術官
首席技術長

Jacob Mellor 是 Iron Software 的首席技術官,也是一位富有遠見的工程師,率先開發了 C# PDF 技術。作為 Iron Software 核心程式碼庫的最初開發者,他自公司成立之初便參與塑造了其產品架構,並與執行長 Cameron Rimington 一起將其發展成為一家擁有 50 多名員工、服務於 NASA、特斯拉和全球政府機構的公司。

Jacob 於 1998 年至 2001 年在曼徹斯特大學獲得土木工程一級榮譽學士學位。 1999 年,他在倫敦創辦了自己的第一家軟體公司;2005 年,他創建了自己的第一個 .NET 元件。此後,他專注於解決微軟生態系統中的複雜問題。

他的旗艦產品 IronPDF 和 IronSuite .NET 庫在全球 NuGet 上的安裝量已超過 3000 萬次,其基礎程式碼持續為全球開發者工具提供支援。憑藉 25 年的商業經驗和 41 年的程式設計專長,Jacob 始終致力於推動企業級 C#、Java 和 Python PDF 技術的創新,同時指導下一代技術領導者。