產品比較

IronPDF與PDFNet比較

發佈 2022年11月14日
分享:

1. 簡介

尋找適用於 .NET Framework 的完美 PDF 工具?

在本文中,我們將探討如何在 C# 中處理 PDF 文件 (最受歡迎的程式語言之一)我們將討論兩個在.NET框架下的C#行業領先的PDF工具,並通過代碼示例來比較它們的性能和特性。最後,我們將檢查它們的授權細節並學習如何獲取授權密鑰。

這兩個PDF庫是:

  • PDFNet
  • IronPDF

2. IronPDF

IronPDF 是由 Iron Software 开发的 C# .NET 库,旨在为 C# .NET 开发者解决所有 PDF 问题,仅需一个库。IronPDF 由 Chromium 引擎驱动,具备多种有用且强大的功能,如将 HTML5、JavaScript、CSS 和图像文件转换为 PDF,创建自定义页眉和页脚,并精确显示 PDF,如同在浏览器中一样。IronPDF 允许您从 PDF 文件中读取数据,并将其自动插入到您的 .NET 应用程序和数据存储系统中。您可以将旧 PDF 存储中的内容导入、移动和索引到您的文档管理和业务应用程序中。

2.1. IronPDF 功能

2.1.1. PDF 轉換

此功能使您可以從 HTML、MVC 視圖、Web 表單、HTML 字串和 URL 等多種格式生成 PDF 檔案。

2.1.2. 提取 PDF 內容

在許多情況下,您可以輕鬆從 PDF 提取嵌入的文本。然而,如果這失敗了,您的文本很可能嵌入在圖像中。要掃描文檔中的視覺文本而不是純文本,請使用 IronOCR 圖書館

2.1.3 頁首和頁尾

在創建 PDF 或現有的 PDF 上可以添加頁首和頁尾。使用 Print Options 屬性,您可以為每個文檔頁面創建頁首和頁尾。這些參數在 ChromePdfRenderer 對象上可用。此範例在 .NET Core 控制台應用程式中運行。

2.1.4. PDF 圖像處理

這讓使用者能夠從 PDF 生成照片,以及從照片生成 PDF。它支持圖像提取、各種圖像擴展以及 PDF 打印。

2.1.5. PDF 文件輸入/輸出

IronPDF 也包含 128 位元 PDF 加密、密碼保護的 PDF 鎖定和 PDF 的數位簽名。

2.1.6. PDF 編輯

IronPDF 工具允許您向 PDF 添加水印、添加頁面、刪除頁面、背景、前景等。

2.1.7. 相容性

IronPDF 支援幾乎所有與 C# 相容的操作系統和框架,例如:

  • Windows
  • .NET Core 2.1, 3.0, 3.1, .NET 6 & 5
  • .NET Standard 2.0 通用相容性
  • Azure
  • AWS
  • Docker
  • Linux

3. PDFNet

PDFNet .NET SDK by PDFTron 為任何網絡、移動、桌面或服務器上的框架或應用程式帶來精確的 PDF 處理、註釋、編輯和創建功能。它管理整個文檔和信息管理流程,無需第三方服務器依賴,全部在您的基礎建設內部實現。PDFTron 的網絡平台配備了支持平台的 JS 版本以及所有 PDF SDK 的演示許可密鑰。

PDFNet 最顯著的好處之一是它真正具有跨平台功能,允許我們的用戶簡單地將 PDF 相容性和相關的業務功能添加到他們的工作流程和應用程式中,無論是在不同的移動和桌面環境中使用,幾乎使用相同的接口。

3.1. PDFNet SDK 功能

3.1.1. 兼容性

PDFNet SDK 與許多平台和框架兼容。為了確保平台的一致性,JavaScript API 以與 PDFNet API 相同的方式使用。SDK 的 Node.js 和 Electron 版本也可用。此軟件包需要非受控外掛二進制文件。

3.1.2. 編輯和查看

為使用者在線上、行動和桌面平台上提供安全、可擴展和高保真度的PDF閱讀和編輯功能。

3.1.3 簽署

建立自訂的簽署程序。數位簽署的文件可以認證、驗證和封存。

3.1.4. 真正的編輯

從文件中刪除敏感數據,例如個人信息或個人健康信息,同時保持文件可搜索。

3.1.5. 頁面操作

頁面可以新增、刪除或重新排列。文件可以組合、合併或分割為多個部分。在同一個閱讀器中或並排查看多個文件。

4. 在 Visual Studio 中建立新專案

在本文中,我們將使用控制台應用程式來生成 PDF 文件。

開啟 Visual Studio 軟體並進入“文件”選單。選擇“新專案”,然後選擇控制台應用程式。

在適當的文本框中輸入專案名稱並選擇路徑。然後,點擊“建立”按鈕。選擇所需的 .NET 框架,如下圖所示:

IronPDF 與 PDFNet 之間的比較,圖 1

Visual Studio 專案現在將生成控制台應用程式的結構。完成後,它將打開 program.cs 文件,您可以在其中編寫和執行源代碼。

IronPDF 和 PDFNet 的比較,圖2

現在我們可以添加庫並測試程序。

5. 安裝 IronPDF 函式庫

IronPDF 函式庫可以透過四種不同的方式下載和安裝。這些方式分別是:

  • 使用 Visual Studio 的 NuGet 套件管理工具
  • 使用 Visual Studio 命令行
  • 從 NuGet 網頁直接下載
  • 從 IronPDF 網頁直接下載

5.1 使用 Visual Studio NuGet 套件管理器

Visual Studio 軟體提供 NuGet 套件管理器選項,可以將套件直接安裝到解決方案中。以下螢幕截圖顯示了如何打開 NuGet 套件管理器。

IronPDF與PDFNet比較,圖3

在打開的套件管理 GUI 中,點擊「瀏覽」標籤並搜索「IronPDF:」

IronPDF 與 PDFNet 比較,圖4

在上面的圖片中,我們可以看到搜索結果中的相關套件列表。選擇IronPDF選項並將該套件安裝到我們的解決方案中。

5.2 使用 Visual Studio 命令列

  • 在 Visual Studio 菜單中,前往 工具 > NuGet 套件管理器 > 套件管理器主控台
IronPDF與PDFNet比較,第五圖

  • 在套件管理器主控台標籤頁中輸入以下行:
Install-Package IronPdf

現在將在專案中安裝 IronPDF 套件。

IronPDF與PDFNet比較,圖6

5.3 直接從 NuGet 網頁下載

第三種方式是直接從網頁下載 NuGet 套件。

  • 導航到 IronPDF NuGet Gallary 頁面
  • 從右側菜單中選擇下載包選項。
  • 雙擊下載的包;它將自動安裝。
  • 接下來,重新加載解決方案並在項目中開始使用它。

5.4 直接從 IronPDF 網頁下載

點擊 這裡 從網頁直接下載最新套件。下載完成後,按照以下步驟將套件添加到專案中。

  • 右鍵點擊解決方案視窗中的專案。
  • 然後,選擇參考選項並瀏覽下載參考的位置。
  • 接著,點擊確定以添加參考。

6. 安裝 PDFNet SDK

PDFNet SDK 可以通過四種不同的方式下載和安裝:

  • 使用 Visual Studio 的 NuGet 套件管理工具。
  • 使用 Visual Studio 命令行。
  • 從 NuGet 網頁直接下載。
  • 使用 PDFNetLoader.dll

6.1. 使用 Visual Studio NuGet 套件管理器

如前所述,前往 Visual Studio 的工具並開啟 NuGet 套件管理器。會出現一個列表——點擊管理解決方案的 NuGet 套件。

IronPDF 與 PDFNet 的比較,圖 7

將會出現一個帶有搜尋欄的視窗。搜尋 PDFNet 並將其安裝到專案中。

6.2. 使用 Visual Studio 命令行

  • 在 Visual Studio 菜单中,转到 工具 > NuGet 套件管理器 > 套件管理器控制台
  • 在套件管理器控制台选项卡中输入以下内容:
Install-Package PDFNet ---Version 9.2.0
IronPDF與PDFNet之比較,圖8

6.3. 從 NuGet 網頁直接下載

第三種方式是直接從網頁下載 NuGet 套件。

  • 導航到 PDFNet NuGet 套件網頁。
  • 從右邊選單中選擇下載套件選項。
  • 雙擊下載的套件以開始安裝過程。

6.4. 使用 PDFNetLoader.dll

您也可以使用 PDFNetLoader.dll 文件安装 PDFNet API。從這裡下載: GitHub下載套件,將它放在專案的 bin 文件夾中,然後運行它。在您的 Visual Studio 專案中,將 PDFNetLoader.dll 添加為參考。

7. 列印 PDF 檔案 (程式碼範例)

列印 PDF 檔案是現代應用程式中處理 PDF 時必備的功能。本文將探討如何使用兩種工具來列印 PDF 檔案。

7.1. 使用 IronPDF 列印 PDF 文件

IronPDF 透過將 PDF 發送到電腦的預設打印機來列印。這將打開 Windows 打印介面——只需點擊打印便可完成操作。

using IronPdf;

// Create a new PDF and print it
var Renderer = new IronPdf.ChromePdfRenderer();
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");

// Send the PDF to the default printer to print
Pdf.Print(300, false);
using IronPdf;

// Create a new PDF and print it
var Renderer = new IronPdf.ChromePdfRenderer();
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");

// Send the PDF to the default printer to print
Pdf.Print(300, false);
Imports IronPdf

' Create a new PDF and print it
Private Renderer = New IronPdf.ChromePdfRenderer()
Private Pdf As PdfDocument = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")

' Send the PDF to the default printer to print
Pdf.Print(300, False)
VB   C#

7.2. 使用 PDFNet 打印 PDF 檔案

PDFTron 的 PDFNet SDK 也提供打印功能。以下是使用 PDFNet 打印 PDF 檔案的源代码片段。

using System;
using System. Drawing;
using System.Drawing.Printing;

using pdftron;
using pdftron.PDF;
using pdftron.Common;
using pdftron.Filters;

namespace PDFPrintTestCS
{
    Console.WriteLine("Opening the input file...");
    using (pdfdoc = new PDFDoc(input_path + "tiger.pdf"))
    {
        pdfdoc.InitSecurityHandler();
        Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...");
        PrinterMode printerMode = new PrinterMode();
        printerMode.SetAutoCenter(true);
        printerMode.SetAutoRotate(true);
        printerMode.SetCollation(true);
        printerMode.SetCopyCount(1);
        printerMode.SetDPI(300); // regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
        printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto);
        printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom);
        printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
        printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations);
        printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
        printerMode.SetOutputPageBorder(false);
        printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium);
        printerMode.SetPaperSize(new Rect(0, 0, 612, 792));
        PageSet pagesToPrint = new PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all);
        Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, null);
    }
}
using System;
using System. Drawing;
using System.Drawing.Printing;

using pdftron;
using pdftron.PDF;
using pdftron.Common;
using pdftron.Filters;

namespace PDFPrintTestCS
{
    Console.WriteLine("Opening the input file...");
    using (pdfdoc = new PDFDoc(input_path + "tiger.pdf"))
    {
        pdfdoc.InitSecurityHandler();
        Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...");
        PrinterMode printerMode = new PrinterMode();
        printerMode.SetAutoCenter(true);
        printerMode.SetAutoRotate(true);
        printerMode.SetCollation(true);
        printerMode.SetCopyCount(1);
        printerMode.SetDPI(300); // regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
        printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto);
        printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom);
        printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
        printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations);
        printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
        printerMode.SetOutputPageBorder(false);
        printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium);
        printerMode.SetPaperSize(new Rect(0, 0, 612, 792));
        PageSet pagesToPrint = new PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all);
        Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, null);
    }
}
Imports System
Imports System.Drawing
Imports System.Drawing.Printing

Imports pdftron
Imports pdftron.PDF
Imports pdftron.Common
Imports pdftron.Filters

Namespace PDFPrintTestCS
	Console.WriteLine("Opening the input file...")
	pdfdoc = New PDFDoc(input_path & "tiger.pdf")
	Using pdfdoc
		pdfdoc.InitSecurityHandler()
		Console.WriteLine("Printing the input file using PDF.Print.StartPrintJob...")
		Dim printerMode As New PrinterMode()
		printerMode.SetAutoCenter(True)
		printerMode.SetAutoRotate(True)
		printerMode.SetCollation(True)
		printerMode.SetCopyCount(1)
		printerMode.SetDPI(300) ' regardless of ordering, an explicit DPI setting overrides the OutputQuality setting
		printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_Auto)
		printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1, PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom)
		printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait)
		printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations)
		printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale)
		printerMode.SetOutputPageBorder(False)
		printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium)
		printerMode.SetPaperSize(New Rect(0, 0, 612, 792))
		Dim pagesToPrint As New PageSet(1, pdfdoc.GetPageCount(), PageSet.Filter.e_all)
		Print.StartPrintJob(pdfdoc, "", pdfdoc.GetFileName(), "", pagesToPrint, printerMode, Nothing)
	End Using
End Namespace
VB   C#

8. 從 HTML 製作 PDF

這兩個庫都具有 HTML 到 PDF 的轉換功能,但方法略有不同。

8.1. 使用 IronPDF 由 HTML 製作 PDF

IronPDF 不需要使用 JSON 或加密機制。IronPDF 支援多種方法。例如:

HTML 檔案轉換為 PDF

using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf");
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("pixel-perfect.pdf")
VB   C#

URL轉PDF

using IronPdf;
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
using IronPdf;
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
Imports IronPdf
Private Renderer As New IronPdf.ChromePdfRenderer()
Private Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
Pdf.SaveAs("url.pdf")
VB   C#
IronPDF 與 PDFNet 的比較,圖 9

8.2. 使用 PDFNet 從 HTML 製作 PDF

PDFNet 也提供使用頁面轉換和 URL 轉換的 HTML 到 PDF 轉換功能。由於代碼較長,我們這裡僅給出一個示例。

class HTML2PDFSample
{
    private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
    static HTML2PDFSample() {}

    static void Main(string [] args)
    {
        string output_path = "../../../../TestFiles/Output/html2pdf_example";
        string host = "https://www.pdftron.com";
        string page0 = "/";
        string page1 = "/support";
        string page2 = "/blog";
        HTML2PDF.SetModulePath("../../../../../Lib");

        if (!HTML2PDF.IsModuleAvailable())
        {
            Console.WriteLine();
            Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.");
            Console.WriteLine("-------------------------------");
            Console.WriteLine("The HTML2PDF module is an optional add-on, available for download");
            Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
            Console.WriteLine("module, ensure that the SDK is able to find the required files");
            Console.WriteLine("using the HTML2PDF.SetModulePath() function.");
            Console.WriteLine();
            return;
        }
        try
        {
            using (PDFDoc doc = new PDFDoc())
            {
                if ( HTML2PDF.Convert(doc, host + page0) )
                    doc.Save(output_path + "_01.pdf", SDFDoc.SaveOptions.e_linearized);
                else
                    Console.WriteLine("Conversion failed.");
            }
        }
        catch (PDFNetException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
class HTML2PDFSample
{
    private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
    static HTML2PDFSample() {}

    static void Main(string [] args)
    {
        string output_path = "../../../../TestFiles/Output/html2pdf_example";
        string host = "https://www.pdftron.com";
        string page0 = "/";
        string page1 = "/support";
        string page2 = "/blog";
        HTML2PDF.SetModulePath("../../../../../Lib");

        if (!HTML2PDF.IsModuleAvailable())
        {
            Console.WriteLine();
            Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.");
            Console.WriteLine("-------------------------------");
            Console.WriteLine("The HTML2PDF module is an optional add-on, available for download");
            Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
            Console.WriteLine("module, ensure that the SDK is able to find the required files");
            Console.WriteLine("using the HTML2PDF.SetModulePath() function.");
            Console.WriteLine();
            return;
        }
        try
        {
            using (PDFDoc doc = new PDFDoc())
            {
                if ( HTML2PDF.Convert(doc, host + page0) )
                    doc.Save(output_path + "_01.pdf", SDFDoc.SaveOptions.e_linearized);
                else
                    Console.WriteLine("Conversion failed.");
            }
        }
        catch (PDFNetException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
Friend Class HTML2PDFSample
	Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()
	Shared Sub New()
	End Sub

	Shared Sub Main(ByVal args() As String)
		Dim output_path As String = "../../../../TestFiles/Output/html2pdf_example"
		Dim host As String = "https://www.pdftron.com"
		Dim page0 As String = "/"
		Dim page1 As String = "/support"
		Dim page2 As String = "/blog"
		HTML2PDF.SetModulePath("../../../../../Lib")

		If Not HTML2PDF.IsModuleAvailable() Then
			Console.WriteLine()
			Console.WriteLine("Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.")
			Console.WriteLine("-------------------------------")
			Console.WriteLine("The HTML2PDF module is an optional add-on, available for download")
			Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this")
			Console.WriteLine("module, ensure that the SDK is able to find the required files")
			Console.WriteLine("using the HTML2PDF.SetModulePath() function.")
			Console.WriteLine()
			Return
		End If
		Try
			Using doc As New PDFDoc()
				If HTML2PDF.Convert(doc, host & page0) Then
					doc.Save(output_path & "_01.pdf", SDFDoc.SaveOptions.e_linearized)
				Else
					Console.WriteLine("Conversion failed.")
				End If
			End Using
		Catch e As PDFNetException
			Console.WriteLine(e.Message)
		End Try
	End Sub
End Class
VB   C#
IronPDF與PDFNet的比較,圖10

9. 授權

IronPDF 是一個提供免費開發者授權的函式庫。IronPDF 還提供特殊的價格結構:輕量包從 $749 起步,沒有隱藏費用。此外,還可以重新分發 SaaS 和 OEM 產品。所有授權都包含30天的退款保證、一年的軟體支援和升級、開發/測試/預備/生產有效期,以及永久授權 (一次性購買). IronPDF 授權提供用戶所需的最佳效能。前往這個 連結 查看 IronPDF 的完整定價結構和授權。

IronPDF 與 PDFNet 的比較,圖 9

PDFTron PDFNet SDK 提供多種定制於您業務需求的授權選項。三種類型的授權包含企業和 OEM 再發行。企業授權僅供組織使用,不能用於應用程式發行。授權中也包含需要檔案系統存取的額外 API。所有授權都附有授權金鑰。三種類型的授權是:

  • Viewer
  • Viewer & Annotation
  • Core SDK

若需進一步了解他們的授權結構,請訪問此網站 連結.

10. 結論

IronPDF 提供了豐富的功能和功能來處理 PDF 文件,並將它們轉換為不同的格式。從 HTML 到 PDF 的轉換以矢量格式生成,適合高品質的商業印刷。因此,您將獲得清晰、高品質的 PDF。授權和定價信息可以在網站上找到。

與 IronPDF 相似,PDFNet 也幫助進行 PDF 文件的轉換、註釋、簽名、填寫、轉換和編輯。它支持多個平台,包括 Windows、IOS、Android、WEB 和 Linux。對於生產使用,PDFNet SDK 需要產品密鑰。

IronPDF 的授權以開發者為中心,這意味著您需要根據將使用該產品的開發者數量獲取授權。另一方面,PDFNet 授權的工作方式不同,它是基於功能的授權。這意味著您需要獲取支持所需功能的授權。IronPDF 授權包括所有功能。而對於 PDFNet,有些功能(如文件轉換)需要作為附加功能購買。

IronPDF 庫以有組織的方式提供功能,使得使用幾行代碼就能完成大型任務代碼的編寫變得容易。目前,Iron Software 提供五合一工具包,只需支付兩個的價格。包含在 IronSuite 中的工具有:

請訪問此鏈接以探索 IronSuite

< 上一頁
IronPDF 與 GroupDocs 的比較
下一個 >
IronPDF與PSPDFKit的比較

準備開始了嗎? 版本: 2024.10 剛剛發布

免費 NuGet 下載 總下載次數: 10,993,239 查看許可證 >