比較

GrabzIt與IronPDF:技術比較指南

當.NET開發人員需要PDF功能時,他們經常遇到Pdfium.NET(或PdfiumViewer),這是圍繞Google的PDFium渲染引擎的.NET包裝層。這篇比較文章檢視Pdfium與IronPDF,分析它們在架構上的差異、功能完整性以及符合現代應用程式需求的適合性。

什麼是Pdfium?

Pdfium.NET是圍繞Google的PDFium程式庫的.NET包裝層,最初為Chromium開發。 這個程式庫在PDF渲染方面表現出色,能夠在.NET應用程式中以高保真度顯示PDF文件。 它提供查看PDF、提取文字和將頁面渲染為圖像的功能。

然而,Pdfium的功能受其專注於渲染的架構的根本限制。 這個程式庫設計用來顯示PDF,而不是建立或修改它們。 這就為需要PDF生成、文件合併或內容修改的應用程式創造了顯著的差距。

Pdfium.NET的主要特點包括:

  • 查看和渲染專注:在以高保真度顯示PDF內容方面表現出色
  • 性能:使用Google的PDFium進行高效渲染
  • 本機二進制依賴:需要平台特定的PDFium二進制文件(x86/x64)
  • 佈署複雜性:必須按平台打包和管理本機DLL

什麼是 IronPDF?

IronPDF是一個完整的.NET程式庫,提供完整的PDF生命周期管理。 ChromePdfRenderer類使用基於Chromium的現代引擎從HTML、CSS和JavaScript建立PDF,而PdfDocument類提供廣泛的操作能力。

與Pdfium僅專注於渲染不同,IronPDF處理PDF建立、操作、合併、水印、安全性和文字提取——所有這些都在單個程式庫中。 完全托管的架構消除了本機二進制依賴,簡化了跨平台的佈署。

架構比較

Pdfium和IronPDF之間的根本區別在於範圍範疇:僅渲染與完整的PDF解決方案。

方面Pdfium.NETIronPDF
主要焦點渲染/查看完整的PDF解決方案
PDF建立✓ (HTML, URL, 圖像)
PDF 操作✓ (合併, 切分, 編輯)
HTML到PDF✓ (Chromium引擎)
水印
頁眉/頁腳
表格填寫
安全
本機相依性需要無(完全托管)
跨平台複雜的設置自動

對於僅需PDF查看的應用程式而言,Pdfium可能已經足夠。對於需要PDF生成、操作或任何建立功能的應用程式,IronPDF提供了完整的解決方案。

HTML到PDF轉換

HTML到PDF的轉換展示了這些程式庫之間的基本功能缺口。

Pdfium HTML到PDF的方式:

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System.IO;
using System.Drawing.Printing;

// Note: PdfiumViewer is primarily for viewing/rendering PDFs, not creating them from HTML
// For HTML to PDF with Pdfium.NET, you would need additional libraries
// This example shows a limitation of Pdfium.NET
class Program
{
    static void Main()
    {
        // Pdfium.NET does not have native HTML to PDF conversion
        // You would need to use a separate library to convert HTML to PDF
        // then use Pdfium for manipulation
        string htmlContent = "<h1>Hello World</h1>";

        // This functionality is not directly available in Pdfium.NET
        Console.WriteLine("HTML to PDF conversion not natively supported in Pdfium.NET");
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System.IO;
using System.Drawing.Printing;

// Note: PdfiumViewer is primarily for viewing/rendering PDFs, not creating them from HTML
// For HTML to PDF with Pdfium.NET, you would need additional libraries
// This example shows a limitation of Pdfium.NET
class Program
{
    static void Main()
    {
        // Pdfium.NET does not have native HTML to PDF conversion
        // You would need to use a separate library to convert HTML to PDF
        // then use Pdfium for manipulation
        string htmlContent = "<h1>Hello World</h1>";

        // This functionality is not directly available in Pdfium.NET
        Console.WriteLine("HTML to PDF conversion not natively supported in Pdfium.NET");
    }
}
Imports PdfiumViewer
Imports System.IO
Imports System.Drawing.Printing

' Note: PdfiumViewer is primarily for viewing/rendering PDFs, not creating them from HTML
' For HTML to PDF with Pdfium.NET, you would need additional libraries
' This example shows a limitation of Pdfium.NET
Class Program
    Shared Sub Main()
        ' Pdfium.NET does not have native HTML to PDF conversion
        ' You would need to use a separate library to convert HTML to PDF
        ' then use Pdfium for manipulation
        Dim htmlContent As String = "<h1>Hello World</h1>"

        ' This functionality is not directly available in Pdfium.NET
        Console.WriteLine("HTML to PDF conversion not natively supported in Pdfium.NET")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF的HTML轉PDF方法:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim htmlContent As String = "<h1>Hello World</h1>"

        Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
        pdf.SaveAs("output.pdf")

        Console.WriteLine("PDF created successfully")
    End Sub
End Class
$vbLabelText   $csharpLabel

Pdfium不能從HTML建立PDF——根本不支持此功能。 需要HTML到PDF轉換的應用程式需要將Pdfium與其他程式庫結合,造成複雜性和潛在的相容性問題。

IronPDF的ChromePdfRenderer使用現代Chromium引擎來轉換HTML內容,全面支持CSS3、Flexbox、Grid和JavaScript執行,從網頁內容生成高保真PDF輸出。

PDF合併

文件合併展示了另一個顯著的能力缺口。

Pdfium合併方式:

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

// Note: PdfiumViewer does not have native PDF merging functionality
// You would need to use additional libraries or implement custom logic
class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        // PdfiumViewer is primarily for rendering/viewing
        // PDF merging is not natively supported
        // You would need to use another library like iTextSharp or PdfSharp

        Console.WriteLine("PDF merging not natively supported in PdfiumViewer");
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

// Note: PdfiumViewer does not have native PDF merging functionality
// You would need to use additional libraries or implement custom logic
class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        // PdfiumViewer is primarily for rendering/viewing
        // PDF merging is not natively supported
        // You would need to use another library like iTextSharp or PdfSharp

        Console.WriteLine("PDF merging not natively supported in PdfiumViewer");
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Collections.Generic

' Note: PdfiumViewer does not have native PDF merging functionality
' You would need to use additional libraries or implement custom logic
Class Program
    Shared Sub Main()
        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        ' PdfiumViewer is primarily for rendering/viewing
        ' PDF merging is not natively supported
        ' You would need to use another library like iTextSharp or PdfSharp

        Console.WriteLine("PDF merging not natively supported in PdfiumViewer")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF合併方法:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        var pdf = PdfDocument.Merge(pdfFiles);
        pdf.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string> 
        { 
            "document1.pdf", 
            "document2.pdf", 
            "document3.pdf" 
        };

        var pdf = PdfDocument.Merge(pdfFiles);
        pdf.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic

Module Program
    Sub Main()
        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        Dim pdf = PdfDocument.Merge(pdfFiles)
        pdf.SaveAs("merged.pdf")

        Console.WriteLine("PDFs merged successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

Pdfium不能合併PDF文件——此程式庫完全缺乏該功能。 需要PDF合併的應用程式需要其他程式庫,增加了依賴和複雜性。

IronPDF的PdfDocument物件,在一個方法調用中將它們合併成一個文件。

文字提取

文字提取是兩個程式庫都提供功能的一個方面,儘管它們的方法和能力不同。

Pdfium文字提取方式:

// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // Note: PdfiumViewer has limited text extraction capabilities
                // Text extraction requires additional work with Pdfium.NET
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // Note: PdfiumViewer has limited text extraction capabilities
                // Text extraction requires additional work with Pdfium.NET
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Text

Module Program
    Sub Main()
        Dim pdfPath As String = "document.pdf"

        Using document = PdfDocument.Load(pdfPath)
            Dim text As New StringBuilder()

            For i As Integer = 0 To document.PageCount - 1
                ' Note: PdfiumViewer has limited text extraction capabilities
                ' Text extraction requires additional work with Pdfium.NET
                Dim pageText As String = document.GetPdfText(i)
                text.AppendLine(pageText)
            Next

            Console.WriteLine(text.ToString())
        End Using
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDF文字提取方式:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim pdfPath As String = "document.pdf"

        Dim pdf = PdfDocument.FromFile(pdfPath)
        Dim text As String = pdf.ExtractAllText()

        Console.WriteLine(text)
    End Sub
End Class
$vbLabelText   $csharpLabel

Pdfium通過GetPdfText()提供文字提取,需要手動遍歷頁面和StringBuilder連接。 文件指出,PdfiumViewer具有"有限的文字提取能力",需要額外的工作。

IronPDF的ExtractAllText()方法從所有頁面中提取所有文字,在一次調用中提供一個更簡單的API以應對常見的用例。 對於每頁存取,IronPDF還提供pdf.Pages[index].Text

API映射參考

對於考慮從Pdfium遷移到IronPDF的團隊而言,了解API映射有助於估計工作量。

文件載入

Pdfium.NETIronPDF
PdfDocument.Load(path)PdfDocument.FromFile(path)
PdfDocument.Load(stream)PdfDocument.FromStream(stream)
document.PageCountdocument.PageCount
document.Pages[index]document.Pages[index]

文字提取

Pdfium.NETIronPDF
document.GetPdfText(pageIndex)document.Pages[index].Text
(手動迴圈)document.ExtractAllText()

保存文件

Pdfium.NETIronPDF
document.Save(path)document.SaveAs(path)
(無法使用)document.BinaryData

Pdfium中不可用的功能

IronPDF功能描述
ChromePdfRenderer.RenderHtmlAsPdf()從 HTML 建立 PDF
ChromePdfRenderer.RenderUrlAsPdf()從 URL 建立 PDF
PdfDocument.Merge()合併多個PDF
pdf.CopyPages()提取特定頁面
pdf.ApplyWatermark()新增水印
pdf.SecuritySettings密碼保護
pdf.SignWithDigitalSignature()數位簽名

本機二進制依賴

一個顯著的架構差異在於依賴管理。

Pdfium佈署結構:

MyApp/
├── bin/
│   ├── MyApp.dll
│   ├── Pdfium.NET.dll
│   ├── x86/
│   │   └── pdfium.dll
│   └── x64/
│       └── pdfium.dll
├── runtimes/
│   ├── win-x86/native/
│   │   └── pdfium.dll
│   └── win-x64/native/
│       └── pdfium.dll

IronPDF佈署結構:

MyApp/
├── bin/
│   ├── MyApp.dll
│   └── IronPdf.dll  # 全部包含

Pdfium需要打包和管理平台特定的本機二進制文件。 這增加了佈署的複雜性,特別是對於跨平台應用程式或容器化環境。 每個目標平台都需要正確的本機DLL,應用程式必須在運行時正確載入相應的版本。

IronPDF的完全托管架構消除了這些問題。 該程式庫內部處理其依賴,簡化了在Windows、Linux和macOS上的佈署。

功能比較總結

Pdfium和IronPDF之間的範圍差異涵蓋了幾乎所有超出基本查看的PDF操作。

功能Pdfium.NETIronPDF
載入 PDF
渲染為圖像
提取文字✓ (基本)✓ (高級)
頁面資訊
來自HTML建立
來自URL建立
合併PDFs
切分PDF
新增水印
頁眉/頁腳
表單填寫
數位簽名
密碼保護
本機依賴需要None
跨平台複雜自動

需要水印頁眉和頁腳或安全設置的應用程式無法僅靠Pdfium實現。

當團隊考慮從Pdfium轉開到IronPDF時

多個因素驅使團隊評估IronPDF作為Pdfium的替代方案:

PDF建立需求: Pdfium無法建立PDF。 需要從HTML模板、報告或網頁內容生成PDF的應用程式需要其他程式庫。 IronPDF提供完整的PDF建立,使用現代Chromium引擎。

文件操作需要: Pdfium無法合併、分割或修改PDF內容。 隨著應用程式的成熟,需求往往超越查看,包括文件組裝、頁面擷取或內容修改。

佈署簡化: 管理跨平台的本機Pdfium二進制文件為構建管道、佈署過程和容器化增加了複雜性。 IronPDF的托管架構消除了這一複雜性。

功能擴展: 開始時雖然僅需查看,但應用程式通常需要水印、安全設置或表格填寫功能。 將這些功能新增到基於Pdfium的應用程式需要其他程式庫,而IronPDF原生提供這些功能。

跨平台一致性: Pdfium為每個目標環境需要平台特定的二進制管理。 IronPDF的托管程式碼無需平台特定配置即可在Windows、Linux和macOS上保持一致。

安裝比較

Pdfium安裝:

Install-Package PdfiumViewer
Install-Package PdfiumViewer
SHELL

加上手動管理本機二進制文件。

IronPDF安裝:

IronPDF在應用程式啟動時需要進行授權金鑰配置:

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

兩個程式庫均支持.NET Framework和現代.NET版本,確保與目標.NET 10和C# 14的應用程式相容。

做出決策

Pdfium和IronPDF之間的選擇取決於您的應用程式需求:

考慮Pdfium: 需要僅查看和渲染PDF,不需要建立或操作PDF,能夠管理本機二進制依賴,並且擁有簡單文字提取需求。

考慮IronPDF: 需要從HTML或URLs建立PDF,要求PDF操作(合併、分割、水印),需要簡化部署而無本機依賴,需要高級功能(表單、安全、簽名),或者正在構建擁有不斷擴展PDF需求的應用程式。

對於大多數現代應用程式來說,建立和操作PDF的能力是必不可少的。 Pdfium僅專注於渲染,無法在不使用其他程式庫的情況下完成全面的PDF工作流程。 IronPDF的完整解決方案消除了程式庫組合的必要性,並為所有PDF操作提供統一的API。

開始使用 IronPDF

要評估IronPDF以滿足您的PDF需求:

1.安裝IronPDF NuGet包Install-Package IronPdf 2.檢查HTML到PDF教程中的建立模式。

  1. 探索文件裝配所需的PDF合併功能
  2. 查看教程部分以獲取全面的範例

IronPDF文件提供了常見場景的詳細指導,API參考記錄了所有可用的類與方法。

結論

Pdfium和IronPDF在.NET PDF生態系中具有根本不同的目的。 Pdfium在PDF渲染方面表現出色——使用Google的PDFium引擎高保真顯示文件。而IronPDF提供了一個涵蓋建立、操作和渲染的完整PDF解決方案。

對於僅需PDF查看的應用程式而言,Pdfium的專注方式可能合適。 對於需要PDF生成、文件合併、水印或任何建立功能的應用程式而言,IronPDF原生提供這些功能,無需額外的程式庫。

選擇不僅涉及當前需求,還包括預期需求。 應用程式通常從查看開始,但會擴展到需要建立和操作。 從一開始就選擇IronPDF為這些擴展需求提供基礎,並消除了Pdfium引入的本機二進制管理的複雜性。

在選擇這些程式庫時,請評估您完整的PDF需求——當前的和預期的。 Pdfium僅渲染的性質使其在應用程式成熟和需求擴展時顯示出架構上的局限性。

請注意PDFium, PDFSharp, 和iText是其各自所有者的註冊商標。 本網站未與Chromium專案、Google、empira Software GmbH或iText Group相關聯、獲其支持或贊助。所有產品名稱、標誌和品牌是其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時公開的資訊。)}