產品比較

Accusoft Prizmdoc PDF Viewer 教程和比較

發佈 2021年9月2日
分享:

Accusoft PDF Viewer 提供 HTML 轉 PDF 功能以及其他 PDF 編輯和操作任務,用於 .NET。IronPDF 也能以程式化方式完成這些任務,為你的 C# 專案節省時間和精力。

讓我們比較這兩者,找出最適合你的專案。


概述

關於 IronPDF

IronPDF 是一個 C# 的 HTML 轉 PDF 庫。它使工程師能夠執行包括從 HTML 字符串、網頁、URL 等來源創建 PDF 文件,以及設置水印、書籤、頁眉和頁腳等屬性。我們還可以將多個 PDF 文件合併為一個,或將 PDF 頁面轉換為圖像,或相反。

此產品在開發階段免費提供,並提供 30 天的部署試用,以實現項目上線。

您可以從這裡下載檔案項目 連結.

關於 Accusoft PrizmDoc Viewer

PrizmDoc Viewer 是一種用於處理PDF檔案並將其遠端轉換為其他格式的REST API。PrizmDoc可以將100多種不同格式的檔案轉換為PDF,並將PDF轉換為PNG、JPG、TIFF和SVG。它還可以用於在應用程式中包含不同類型的電子簽名選項。

比較表

IronPDFPrizmDoc Viewer
程序化處理 PDF 文件。程序化處理 PDF 文件。
支援 .NET Core 於 Windows、Mac 或 Linux 使用。支援使用 Windows、Mac 或 Linux 的 .NET Core。
在本地運作將文件發送到遠端伺服器。
使用或不使用非同步程式設計。必須使用 `System.Threading.Tasks` 進行非同步編程。
一旦我們在系統中安裝 IronPDF,就可以輕鬆離線工作。必須連接到網際網路以將請求發送到PrizmDoc Viewer伺服器(雲託管或自託管)。
提供許多預定義的功能。提供一些預定義的功能。
通常只需要幾行程式碼。通常需要許多行程式碼。
每個授權計畫中每個項目無限次轉換。每個雲端托管許可方案中的交易次數有限。
開發免費且無時間限制。試用版僅限300次交易。

讓我們安裝這兩個並比較代碼。


步驟 1:安裝

1. 安裝 IronPDF 函式庫

在您的專案中有兩種安裝 IronPDF 的方式,採用哪種方式都沒有差別。

1.1. 下載IronPDF DLL

下載 IronPDF.dll 將其引用添加到您的專案中。完成此操作後,您可以通過以下方式輕鬆訪問命名空間IronPdf

using IronPdf;

現在,您可以輕鬆訪問IronPDF提供的函數和類別。

1.2 透過 NuGet 套件管理器安裝

  • 套件管理器主控台:

    如果您使用的是套件管理器主控台,請運行以下命令:

    :ProductInstall

管理解決方案的套件:

如果您正在使用 GUI NuGet 套件管理器,然後在搜尋欄中瀏覽 IronPDF 並安裝。


安裝來自Accusoft的PrizmDoc Viewer

PrizmDoc Viewer 有兩個部分,一個是稱為 PrizmDoc Server 的伺服器端,它的行為類似 Restful API。另一個是我們的專案,我們通過它呼叫該 API 並獲取回應。

訪問 PrizmDoc 伺服器

從名稱可以看出,這是一個伺服器端應用程式,可以隨著請求獲取文件的基本信息。 (輸入) 並將文件轉換為 PDF 文件,然後將轉換後的 PDF 文件作為回應發送給客戶 (輸出). 這是產品的技術核心,是一個文檔處理和轉換引擎。我們可以通過兩種不同的方式使用它,選擇哪一種方式沒有差別,因為兩者具有相同的編程結構和技術:

  1. 自我托管:

    對於這一選項,您需要自備伺服器,然後您可以 下載 PrizmDoc Server 然後安裝它。閱讀更多 關於如何在 Windows 上安裝 PrizmDoc 伺服器。

注意: 需要至少 32 GB RAM 和 4 核心 CPU,否則您可能會遇到不良體驗。

  1. 雲端託管:

這是一項基於雲的 PrizmDoc Viewer 服務,您不需要安排自己的伺服器。我們將使用它進行比較。為此, 建立您的帳戶 然後首頁將會開啟。您可以從 API Key 菜單中複製 API key,稍後我們會看到如何使用它。

首先,我們會看到使用 PrizmDoc Viewer 將文件轉換為 PDF 文件的基本結構,並且我們將直接使用 WebClientAccusoft server 進行交互。()在 C# 控制台應用程式中。

注意: 以下範例僅用於了解 PrizmDoc 如何處理 PDF 文件。這有點長,因此如果您跳過此範例也沒有問題。 直接進入比較.

Accusoft 工作結構

在此範例中,我們將把 myWebpage.html 轉換為 sample.pdf 檔案。

注意: 我們必須安裝 Newtonsoft 庫並在項目中添加其引用。

首先,將以下庫添加到您的項目中:

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;//install Newtonsoft
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;//install Newtonsoft
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading.Tasks
Imports Newtonsoft.Json.Linq 'install Newtonsoft
VB   C#

然後創建一個公共變數 Accusoft API Key 並將您的 API Key 粘貼在其中,如下所示:

static string ApiKey= "Your-API-KEY";

使用PrizmDoc Viewer處理PDF文件有3個步驟:

1. 上傳文件到PrizmDoc伺服器。

2. 轉換上傳的文件。

3. 從PrizmDoc伺服器下載轉換後的文件。

所以,我們將為每個步驟創建一個單獨的函數。

```cs
static void Main(string [] args)
{
    //---Upload file to Server---
    JObject uploadResults = UploadToServer("myWebpage.html").Result;
    string fileID = (string)uploadResults.SelectToken("fileId");
    string affinityToken = (string)uploadResults.SelectToken("affinityToken");

    //---Convert the uploaded file to PDF---
    JObject convertResults = Convert(affinityToken, fileID).Result;
    string processId = (string)convertResults.SelectToken("processId");
    affinityToken = (string)convertResults.SelectToken("affinityToken");

    //---Check the status that conversion is completed---
    JObject convertStatusresults = ConvertStatus(processId, affinityToken).Result;
    string convertStatus = (string)convertResults.SelectToken("state");

    //---Continuously checking whether conversion completed or not until completed---
    while (!(convertStatus.Equals("complete")))
    {
        System.Threading.Thread.Sleep(30000);
        convertStatusresults = ConvertStatus(processId, affinityToken).Result;
        convertStatus = (string)convertStatusresults.SelectToken("state");
    }

    //---Download the converted file from server---
    string newFileID = (string)convertStatusresults.SelectToken("output.results [0].fileId");
    DownloadFromServer(affinityToken, newFileID, "sample.pdf").Wait();

    Console.WriteLine("PDF file created successfully...!");
    Console.ReadKey();
}

1. 將檔案上傳到伺服器:

public static async Task<JObject> UploadToServer(string fileToUpload)
{
    FileInfo input = new FileInfo(fileToUpload);
    if (input == null)
    {
        throw new ArgumentException("Missing parameter input", "input");
    }
    var fileName = input.Name;
    var endpoint = new Uri("https://api.accusoft.com/PCCIS/V1/WorkFile");
    using (var client = new WebClient())
    {
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Content-Type", "application/octet-stream");
        using (var reader = new BinaryReader(input.OpenRead()))
        {
            var data = reader.ReadBytes((int)reader.BaseStream.Length);
            var results = await client.UploadDataTaskAsync(endpoint, "POST", data);
            string getResult = "";
            getResult = Encoding.ASCII.GetString(results);
            return JObject.Parse(getResult);
        }
    }
}
public static async Task<JObject> UploadToServer(string fileToUpload)
{
    FileInfo input = new FileInfo(fileToUpload);
    if (input == null)
    {
        throw new ArgumentException("Missing parameter input", "input");
    }
    var fileName = input.Name;
    var endpoint = new Uri("https://api.accusoft.com/PCCIS/V1/WorkFile");
    using (var client = new WebClient())
    {
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Content-Type", "application/octet-stream");
        using (var reader = new BinaryReader(input.OpenRead()))
        {
            var data = reader.ReadBytes((int)reader.BaseStream.Length);
            var results = await client.UploadDataTaskAsync(endpoint, "POST", data);
            string getResult = "";
            getResult = Encoding.ASCII.GetString(results);
            return JObject.Parse(getResult);
        }
    }
}
Public Shared Async Function UploadToServer(ByVal fileToUpload As String) As Task(Of JObject)
	Dim input As New FileInfo(fileToUpload)
	If input Is Nothing Then
		Throw New ArgumentException("Missing parameter input", "input")
	End If
	Dim fileName = input.Name
	Dim endpoint = New Uri("https://api.accusoft.com/PCCIS/V1/WorkFile")
	Using client = New WebClient()
		client.Headers.Add("acs-api-key", ApiKey)
		client.Headers.Add("Content-Type", "application/octet-stream")
		Using reader = New BinaryReader(input.OpenRead())
			Dim data = reader.ReadBytes(CInt(reader.BaseStream.Length))
			Dim results = Await client.UploadDataTaskAsync(endpoint, "POST", data)
			Dim getResult As String = ""
			getResult = Encoding.ASCII.GetString(results)
			Return JObject.Parse(getResult)
		End Using
	End Using
End Function
VB   C#

2. 將上傳的檔案轉換成 PDF:

public static async Task<JObject> Convert(string affinityToken, string fileID)
{
    var endpoint = new Uri("https://api.accusoft.com/v2/contentConverters");
    using (var client = new WebClient())
    {
        client.Headers.Add("Content-Type", "application/json");
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        JObject myJson =
            new JObject(
                new JProperty("input",
                    new JObject(
                        new JProperty("sources",
                            new JArray(
                                new JObject(
                                    new JProperty("fileId", fileID)
                                    )
                                )
                            ),
                            new JProperty("dest",
                                new JObject(
                                    new JProperty("format", "pdf")
                                )
                            )
                        )
                    )
                );
            string results = await client.UploadStringTaskAsync(endpoint, "POST", myJson.ToString());
            return JObject.Parse(results);
    }
}
public static async Task<JObject> Convert(string affinityToken, string fileID)
{
    var endpoint = new Uri("https://api.accusoft.com/v2/contentConverters");
    using (var client = new WebClient())
    {
        client.Headers.Add("Content-Type", "application/json");
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        JObject myJson =
            new JObject(
                new JProperty("input",
                    new JObject(
                        new JProperty("sources",
                            new JArray(
                                new JObject(
                                    new JProperty("fileId", fileID)
                                    )
                                )
                            ),
                            new JProperty("dest",
                                new JObject(
                                    new JProperty("format", "pdf")
                                )
                            )
                        )
                    )
                );
            string results = await client.UploadStringTaskAsync(endpoint, "POST", myJson.ToString());
            return JObject.Parse(results);
    }
}
Public Shared Async Function Convert(ByVal affinityToken As String, ByVal fileID As String) As Task(Of JObject)
	Dim endpoint = New Uri("https://api.accusoft.com/v2/contentConverters")
	Using client = New WebClient()
		client.Headers.Add("Content-Type", "application/json")
		client.Headers.Add("acs-api-key", ApiKey)
		client.Headers.Add("Accusoft-Affinity-Token", affinityToken)
		Dim myJson As New JObject(New JProperty("input", New JObject(New JProperty("sources", New JArray(New JObject(New JProperty("fileId", fileID)))), New JProperty("dest", New JObject(New JProperty("format", "pdf"))))))
			Dim results As String = Await client.UploadStringTaskAsync(endpoint, "POST", myJson.ToString())
			Return JObject.Parse(results)
	End Using
End Function
VB   C#

以下 JSON 是 myJson 物件的結果值:

{
  "input": {
    "sources": 
    [
      {"fileId": "Auto Generated FileId Value"}
    ],
    "dest": {
      "format": "pdf"
    }
  }
}

檢查轉換是否完成的狀態

public static async Task<JObject> ConvertStatus(string processId, string affinityToken)
{
    string endpoint = "https://api.accusoft.com/v2/contentConverters/" + processId;
    using (var client = new WebClient())
    {
        client.BaseAddress = endpoint;
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        string results = await client.DownloadStringTaskAsync(endpoint);
        return JObject.Parse(results);
    }
}
public static async Task<JObject> ConvertStatus(string processId, string affinityToken)
{
    string endpoint = "https://api.accusoft.com/v2/contentConverters/" + processId;
    using (var client = new WebClient())
    {
        client.BaseAddress = endpoint;
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        string results = await client.DownloadStringTaskAsync(endpoint);
        return JObject.Parse(results);
    }
}
Public Shared Async Function ConvertStatus(ByVal processId As String, ByVal affinityToken As String) As Task(Of JObject)
	Dim endpoint As String = "https://api.accusoft.com/v2/contentConverters/" & processId
	Using client = New WebClient()
		client.BaseAddress = endpoint
		client.Headers.Add("acs-api-key", ApiKey)
		client.Headers.Add("Accusoft-Affinity-Token", affinityToken)
		Dim results As String = Await client.DownloadStringTaskAsync(endpoint)
		Return JObject.Parse(results)
	End Using
End Function
VB   C#

3. 從伺服器下載轉換後的檔案

public static async Task DownloadFromServer(string affinityToken, string fileId, string outfile)
{
    var endpoint = new Uri("https://api.accusoft.com/PCCIS/V1/WorkFile/" + fileId);

    using (var client = new WebClient())
    {
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        FileInfo output = new FileInfo(outfile);

        using (var writeStream = output.Create())
        {
            var results = await client.DownloadDataTaskAsync(endpoint);
            await writeStream.WriteAsync(results, 0, results.Length);
        }
    }
}
public static async Task DownloadFromServer(string affinityToken, string fileId, string outfile)
{
    var endpoint = new Uri("https://api.accusoft.com/PCCIS/V1/WorkFile/" + fileId);

    using (var client = new WebClient())
    {
        client.Headers.Add("acs-api-key", ApiKey);
        client.Headers.Add("Accusoft-Affinity-Token", affinityToken);
        FileInfo output = new FileInfo(outfile);

        using (var writeStream = output.Create())
        {
            var results = await client.DownloadDataTaskAsync(endpoint);
            await writeStream.WriteAsync(results, 0, results.Length);
        }
    }
}
Public Shared Async Function DownloadFromServer(ByVal affinityToken As String, ByVal fileId As String, ByVal outfile As String) As Task
	Dim endpoint = New Uri("https://api.accusoft.com/PCCIS/V1/WorkFile/" & fileId)

	Using client = New WebClient()
		client.Headers.Add("acs-api-key", ApiKey)
		client.Headers.Add("Accusoft-Affinity-Token", affinityToken)
		Dim output As New FileInfo(outfile)

		Using writeStream = output.Create()
			Dim results = Await client.DownloadDataTaskAsync(endpoint)
			Await writeStream.WriteAsync(results, 0, results.Length)
		End Using
	End Using
End Function
VB   C#

上述示例需要花费大量精力。! 為了減少工作量,Accusoft 引入了一個名為 Accusoft.PrizmDocServerSDK,這是一個包裝 PrizmDoc Server REST API 的封裝。我們來看看如何在我們的 .NET 專案中安裝和使用這個庫。

安裝 Accusoft.PrizmDocServerSDK

有兩種安裝包裝器的方法。

  • 套件管理器控制台:

    如果您使用的是套件管理器控制台,請運行以下命令:

    :InstallCmd install-package Accusoft.PrizmDocServerSDK
  • 為解決方案管理套件:

    如果您使用的是 NuGet 套件管理器的 GUI,請在搜索欄中瀏覽 Accusoft.PrizmDocServerSDK 並安裝它。

現在,您可以輕鬆地存取 Accusoft.PrizmDocServer 命名空間並通過以下方式使用它:

using Accusoft.PrizmDocServer;


操作教程

2. IronPDF vs PrizmDoc Viewer 代碼比較

在閱讀了這兩個組件的介紹和安裝說明後,現在是時候使用這兩個組件進行操作了。為此,我們將採用一些用例並使用這兩個組件進行實現。我們希望這能提供一個簡單易懂的方式來了解雙方的程式結構,並得出哪個最好適合您的專案的結論。


3. 將 HTML 轉換為 PDF 文件

在我們的第一次比較中,讓我們以一個名為 myWebPage.html 的網頁為例,並希望從中生成一個 PDF 文件,然後將其保存到目標位置。

3.1. IronPDF HTML 轉 PDF

/**
HTML to PDF
anchor-ironpdf-html-to-pdf
**/
using IronPdf;
static void Main(string [] args)
{
    //create rendering converter
    var converter = new ChromePdfRenderer();
    //render html file to pdf
    using var PDF = converter.RenderHTMLFileAsPdf("myWebPage.html");
    //save to target location
    PDF.SaveAs("sample.pdf");
}
/**
HTML to PDF
anchor-ironpdf-html-to-pdf
**/
using IronPdf;
static void Main(string [] args)
{
    //create rendering converter
    var converter = new ChromePdfRenderer();
    //render html file to pdf
    using var PDF = converter.RenderHTMLFileAsPdf("myWebPage.html");
    //save to target location
    PDF.SaveAs("sample.pdf");
}
'''
'''HTML to PDF
'''anchor-ironpdf-html-to-pdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
	'create rendering converter
	Dim converter = New ChromePdfRenderer()
	'render html file to pdf
	Dim PDF = converter.RenderHTMLFileAsPdf("myWebPage.html")
	'save to target location
	PDF.SaveAs("sample.pdf")
End Sub
VB   C#

上述程式碼將建立一個 sample.pdf 檔案並儲存到專案的 bin>debug 資料夾。

您也可以像這樣指定任何路徑: PDF.SaveAs("E:/sample.pdf");

閱讀更多 如何使用 IronPDF 處理 PDF 檔案。

現在,我們將使用 PrizmDoc Viewer 進行相同的任務,這樣我們的比較就變得容易了。

3.2. PrizmDoc Viewer HTML to PDF

在PrizmDoc Viewer安裝過程中,我們已經討論過如何獲取Accusoft API Key,現在我們來看看如何使用它。

首先,我們向PrizmDoc服務器發送請求並從中獲得回應。這個過程需要一些時間,所以我們需要使用非同步程式設計。

注意: 在使用PrizmDoc Viewer的雲端服務創建PDF文件時,請確保您的系統已連接到互聯網。

using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    ChromePdfRenderer().GetAwaiter().GetResult();
}
private static async Task ChromePdfRenderer()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    // specify HTML file and convert it to a PDF.
    ConversionResult result = await prizmDocServer.ConvertToPdfAsync("myWebPage.html");
    // Save pdf file to the target location
    await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    ChromePdfRenderer().GetAwaiter().GetResult();
}
private static async Task ChromePdfRenderer()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    // specify HTML file and convert it to a PDF.
    ConversionResult result = await prizmDocServer.ConvertToPdfAsync("myWebPage.html");
    // Save pdf file to the target location
    await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
Imports Accusoft.PrizmDocServer
Imports Accusoft.PrizmDocServer.Conversion
Shared Sub Main(ByVal args() As String)
	ChromePdfRenderer().GetAwaiter().GetResult()
End Sub
Private Shared Async Function ChromePdfRenderer() As Task
	'instantiate PrizmDocServerClient object
	Dim prizmDocServer = New PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY")
	' specify HTML file and convert it to a PDF.
	Dim result As ConversionResult = Await prizmDocServer.ConvertToPdfAsync("myWebPage.html")
	' Save pdf file to the target location
	Await result.RemoteWorkFile.SaveAsync("sample.pdf")
End Function
VB   C#

閱讀更多 關於如何使用 PrizmDoc Viewer。

3.3. HTML 到 PDF 代碼比較

從這些範例中,我們可以看出 IronPDF 是創建 PDF 文件的更簡單方法,且不需要那麼多時間。


4. 圖片轉PDF

在這個比較中,我們使用了一個需要創建PDF文件的案例 圖片, 並且它存在於我們專案的 debug 資料夾中。我們開始使用 IronPDF。

4.1. IronPDF 圖像轉 PDF

/**
Image to PDF
anchor-ironpdf-image-to-pdf
**/
using IronPdf;
static void Main(string [] args)
{
    //specify the image to be convert
    using var converted = ImageToPdfConverter.ImageToPdf("google.png");
    //save PDF file to the target location
    converted.SaveAs("sample.pdf");
}
/**
Image to PDF
anchor-ironpdf-image-to-pdf
**/
using IronPdf;
static void Main(string [] args)
{
    //specify the image to be convert
    using var converted = ImageToPdfConverter.ImageToPdf("google.png");
    //save PDF file to the target location
    converted.SaveAs("sample.pdf");
}
'''
'''Image to PDF
'''anchor-ironpdf-image-to-pdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
	'specify the image to be convert
	Dim converted = ImageToPdfConverter.ImageToPdf("google.png")
	'save PDF file to the target location
	converted.SaveAs("sample.pdf")
End Sub
VB   C#

輸出:

這是使用上述程式碼新創建的 PDF 檔案 sample.pdf 的截圖:

我們可以看到使用 IronPDF 從圖像創建 PDF 文件是多麼容易。現在,我們將使用 PrizmDoc Viewer 執行相同的任務,並查看其生成的 PDF 文件。

4.2. PrizmDoc Viewer 圖片轉 PDF

static void Main(string [] args)
{
    ImageToPDF().GetAwaiter().GetResult();
}
private static async Task ImageToPDF()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //specify the image to be convert
    ConversionResult results = await prizmDocServer.ConvertToPdfAsync("google.png");
    //save pdf file to the target location
    await results.RemoteWorkFile.SaveAsync("sample.pdf");
}
static void Main(string [] args)
{
    ImageToPDF().GetAwaiter().GetResult();
}
private static async Task ImageToPDF()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //specify the image to be convert
    ConversionResult results = await prizmDocServer.ConvertToPdfAsync("google.png");
    //save pdf file to the target location
    await results.RemoteWorkFile.SaveAsync("sample.pdf");
}
Shared Sub Main(ByVal args() As String)
	ImageToPDF().GetAwaiter().GetResult()
End Sub
Private Shared Async Function ImageToPDF() As Task
	'instantiate PrizmDocServerClient object
	Dim prizmDocServer = New PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY")
	'specify the image to be convert
	Dim results As ConversionResult = Await prizmDocServer.ConvertToPdfAsync("google.png")
	'save pdf file to the target location
	Await results.RemoteWorkFile.SaveAsync("sample.pdf")
End Function
VB   C#

輸出:該截圖是從上述代碼新創建的 PDF 文件 sample.pdf

4.3. 圖像轉 PDF 程式碼比較

我們可以看到,只需要用 IronPDF 寫兩行簡單的程式碼。另一方面,使用 PrizmDoc 伺服器,我們必須寫許多行非同步程式碼。IronPDF 的輸出也自動提供一個可用的全頁文檔。


5. 合併 PDF 文件

在這個比較中,假設我們有三個名為 A.pdfB.pdfC.pdf 的 PDF 文件。我們希望將它們合併成一個 PDF 文件,我們可以使用這兩個組件來完成這個任務。首先,我們將看到如何使用 IronPDF 來執行這個任務。

5.1. IronPDF 合併 PDF 文件

/**
Merge PDF Files
anchor-ironpdf-merge-pdf-files
**/
using IronPdf;
using System.Collections.Generic;
static void Main(string [] args)
{
    //create rendering converter  
    var Renderer = new IronPdf.ChromePdfRenderer();
    //create a list of pdf files
    var PDFs = new List<PdfDocument>();
    PDFs.Add(PdfDocument.FromFile("A.pdf"));
    PDFs.Add(PdfDocument.FromFile("B.pdf"));
    PDFs.Add(PdfDocument.FromFile("C.pdf"));
    //merge the list of pdf file
    using PdfDocument PDF = PdfDocument.Merge(PDFs);
    //save merged file to the target location
    PDF.SaveAs("sample.pdf");

    foreach(var pdf in PDFs){
        pdf.Dispose();
    }
}
/**
Merge PDF Files
anchor-ironpdf-merge-pdf-files
**/
using IronPdf;
using System.Collections.Generic;
static void Main(string [] args)
{
    //create rendering converter  
    var Renderer = new IronPdf.ChromePdfRenderer();
    //create a list of pdf files
    var PDFs = new List<PdfDocument>();
    PDFs.Add(PdfDocument.FromFile("A.pdf"));
    PDFs.Add(PdfDocument.FromFile("B.pdf"));
    PDFs.Add(PdfDocument.FromFile("C.pdf"));
    //merge the list of pdf file
    using PdfDocument PDF = PdfDocument.Merge(PDFs);
    //save merged file to the target location
    PDF.SaveAs("sample.pdf");

    foreach(var pdf in PDFs){
        pdf.Dispose();
    }
}
'''
'''Merge PDF Files
'''anchor-ironpdf-merge-pdf-files
'''*
Imports IronPdf
Imports System.Collections.Generic
Shared Sub Main(ByVal args() As String)
	'create rendering converter  
	Dim Renderer = New IronPdf.ChromePdfRenderer()
	'create a list of pdf files
	Dim PDFs = New List(Of PdfDocument)()
	PDFs.Add(PdfDocument.FromFile("A.pdf"))
	PDFs.Add(PdfDocument.FromFile("B.pdf"))
	PDFs.Add(PdfDocument.FromFile("C.pdf"))
	'merge the list of pdf file
	Using PDF As PdfDocument = PdfDocument.Merge(PDFs)
		'save merged file to the target location
		PDF.SaveAs("sample.pdf")
	
'INSTANT VB NOTE: The variable pdf was renamed since Visual Basic will not allow local variables with the same name as parameters or other local variables:
		For Each .pdf_Conflict In PDFs
			.pdf_Conflict.Dispose()
		Next pdf_Conflict
	End Using
End Sub
VB   C#

上述程式碼將會建立一個名為 sample.pdf 的檔案,這個檔案是由 A.pdfB.pdfC.pdf 合併而成。

現在,我們將使用 PrizmDoc Viewer 來完成相同的任務。

5.2. PrizmDoc Viewer 合併 PDF 檔案

using System.Threading.Tasks;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;

static void Main(string [] args)
{
    PdfMerge().GetAwaiter().GetResult();
}
private static async Task PdfMerge()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //pass the list of pdf files to PrizmDoc Server
    ConversionResult result = await prizmDocServer.CombineToPdfAsync(
        new []{
                new ConversionSourceDocument("A.pdf"),
                new ConversionSourceDocument("B.pdf"),
                new ConversionSourceDocument("C.pdf"),
            });
    //save merged file to the target location
    await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
using System.Threading.Tasks;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;

static void Main(string [] args)
{
    PdfMerge().GetAwaiter().GetResult();
}
private static async Task PdfMerge()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //pass the list of pdf files to PrizmDoc Server
    ConversionResult result = await prizmDocServer.CombineToPdfAsync(
        new []{
                new ConversionSourceDocument("A.pdf"),
                new ConversionSourceDocument("B.pdf"),
                new ConversionSourceDocument("C.pdf"),
            });
    //save merged file to the target location
    await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
Imports System.Threading.Tasks
Imports Accusoft.PrizmDocServer
Imports Accusoft.PrizmDocServer.Conversion

Shared Sub Main(ByVal args() As String)
	PdfMerge().GetAwaiter().GetResult()
End Sub
Private Shared Async Function PdfMerge() As Task
	'instantiate PrizmDocServerClient object
	Dim prizmDocServer = New PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY")
	'pass the list of pdf files to PrizmDoc Server
	Dim result As ConversionResult = Await prizmDocServer.CombineToPdfAsync({
		New ConversionSourceDocument("A.pdf"),
		New ConversionSourceDocument("B.pdf"),
		New ConversionSourceDocument("C.pdf")
	})
	'save merged file to the target location
	Await result.RemoteWorkFile.SaveAsync("sample.pdf")
End Function
VB   C#

上述程式碼還會建立一個 sample.pdf 檔案,該檔案是 A.pdfB.pdfC.pdf 檔案的組合。


6. PDF 頁眉與頁腳

在這次比較中,假設我們有一個名為 myWebPage.html 的簡單網頁,該網頁包含以下 HTML 和 CSS:

<html>
<head>
    <style>
        li {
            font-size:x-large;
            color: rgba(156, 89, 13, 0.897);
            list-style:square;
        }
  </style>
</head>
<body>
    <h1 style="text-align: center;">Hello World..!</h1>
    <h1>Main Menu</h1>
    <ul>
        <li>SubMenu 1</li>
        <li>SubMenu 2</li>
        <li>SubMenu 3</li>
        <li>SubMenu 4</li>
        <li>SubMenu 5</li>
    </ul>
</body>
</html>
<html>
<head>
    <style>
        li {
            font-size:x-large;
            color: rgba(156, 89, 13, 0.897);
            list-style:square;
        }
  </style>
</head>
<body>
    <h1 style="text-align: center;">Hello World..!</h1>
    <h1>Main Menu</h1>
    <ul>
        <li>SubMenu 1</li>
        <li>SubMenu 2</li>
        <li>SubMenu 3</li>
        <li>SubMenu 4</li>
        <li>SubMenu 5</li>
    </ul>
</body>
</html>
HTML

我們想將這個網頁轉換成 PDF 文件,設定以下頁首和頁尾屬性:

  • 頁首左側的頁面標題
  • 頁首右側的日期時間
  • 頁尾右側的當前頁數/總頁數

首先,我們將看看如何使用 IronPDF 設定頁首和頁尾。

6.1. IronPDF PDF 標題和頁腳

為了處理 PDF 文件的標題和頁腳,IronPDF 在 ChromePdfRenderer 類別中提供了一個名為 RenderingOptions 的屬性,可以用如下方式使用:

  • 對於標題:

    C# ChromePdfRenderer_Obj.RenderingOptions.TextHeader = new TextHeaderFooter()* 頁腳:

    C# ChromePdfRenderer_Obj.RenderingOptions.TextFooter = new TextHeaderFooter()```

我們可以在初始化 TextHeaderFooter 時設置以下屬性:():

  • CenterText 將文字打印在頁眉或頁腳的中間。
  • LeftText 將文字打印在頁眉或頁腳的左側。
  • RightText 將文字打印在頁眉或頁腳的右側。
  • DrawDividerLine 繪製一條將頁面內容與頁眉或頁腳分開的線。
  • FontFamily 指定頁眉或頁腳的字體系列。
  • FontSize 指定頁眉或頁腳的字體大小。
  • Spacing 調整頁面內容與頁眉或頁腳之間的空間。

以下一些預定義的屬性對設置頁眉或頁腳內容非常有幫助。它可以用大括號寫{ }` 如下:

  • {頁面} 在頁首或頁尾列印當前頁碼。
  • {總頁數}它在頁眉或頁腳中列印總頁數。**
  • {網址}它用來列印已渲染頁面的 URL。**
  • {日期}它在頁眉或頁腳打印當前日期。
  • {時間}它在頁眉或頁腳打印當前時間。
  • {html-標題}它在頁眉或頁腳中列印已渲染網頁的標題
  • {pdf-title}它會在頁眉或頁腳中列印文件標題。

閱讀更多 詳細說明如何使用 IronPDF 處理頁首和頁尾。

讓我們看下面的例子來實現這個用例,並演示如何使用上述屬性來設置 PDF 文件的頁首和頁尾。

/**
Set Header and Footer
anchor-ironpdf-pdf-header-and-footer
**/
using IronPdf;
static void Main(string [] args)
{
    //create rendering converter
    var converter = new ChromePdfRenderer();
    //setting Header properties
    converter.RenderingOptions.TextHeader = new TextHeaderFooter()
    {
        DrawDividerLine = true,
        LeftText = "Page Title",
        RightText = "{date} {time}",
        FontSize = 13
    };
    //setting footer properties
    converter.RenderingOptions.TextFooter = new TextHeaderFooter()
    {
        RightText = "Page {page} of {total-pages}",
        FontSize = 12
    };
    //specify the file to be converted
    using var PDF = converter.RenderHTMLFileAsPdf("myWebPage.html");
    //save to target location
    PDF.SaveAs("sample.pdf");
}
/**
Set Header and Footer
anchor-ironpdf-pdf-header-and-footer
**/
using IronPdf;
static void Main(string [] args)
{
    //create rendering converter
    var converter = new ChromePdfRenderer();
    //setting Header properties
    converter.RenderingOptions.TextHeader = new TextHeaderFooter()
    {
        DrawDividerLine = true,
        LeftText = "Page Title",
        RightText = "{date} {time}",
        FontSize = 13
    };
    //setting footer properties
    converter.RenderingOptions.TextFooter = new TextHeaderFooter()
    {
        RightText = "Page {page} of {total-pages}",
        FontSize = 12
    };
    //specify the file to be converted
    using var PDF = converter.RenderHTMLFileAsPdf("myWebPage.html");
    //save to target location
    PDF.SaveAs("sample.pdf");
}
'''
'''Set Header and Footer
'''anchor-ironpdf-pdf-header-and-footer
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
	'create rendering converter
	Dim converter = New ChromePdfRenderer()
	'setting Header properties
	converter.RenderingOptions.TextHeader = New TextHeaderFooter() With {
		.DrawDividerLine = True,
		.LeftText = "Page Title",
		.RightText = "{date} {time}",
		.FontSize = 13
	}
	'setting footer properties
	converter.RenderingOptions.TextFooter = New TextHeaderFooter() With {
		.RightText = "Page {page} of {total-pages}",
		.FontSize = 12
	}
	'specify the file to be converted
	Dim PDF = converter.RenderHTMLFileAsPdf("myWebPage.html")
	'save to target location
	PDF.SaveAs("sample.pdf")
End Sub
VB   C#

輸出: 透過以上代碼新建的 PDF 文件 sample.pdf 的螢幕截圖:

我們可以看到使用直觀的語言在 IronPDF 中創建 PDF 檔案的同時,處理頁首和頁尾是多麼簡單。現在,我們將了解如何使用 PrizmDoc Viewer 設定頁首和頁尾。

6.2. PrizmDoc Viewer PDF 頁首和頁尾

PrizmDoc Viewer 提供 HeaderFooterOptions 類別來處理頁首和頁尾,其具有以下屬性:

  • Lines 它指定了行(s) 頁首和頁尾(當你理解以下示例時會更清楚),每一行具有以下屬性:
  • Left 在頁首或頁尾行的左側打印文本。
  • Center 在頁首或頁尾行的中間打印文本。
  • Right 在頁首或頁尾行的右側打印文本。
  • FontFamily 指定頁首或頁尾文本的字體系列。
  • FontSize 指定頁首或頁尾文本的字體大小。
  • Color 指定頁首或頁尾文本的顏色。

閱讀更多 關於如何使用PrizmDoc服務器設置PDF頁面的頁眉和頁腳。

讓我們看看如何使用上述屬性實現我們的用例。

using System.Threading.Tasks;
using System.Collections.Generic;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    SetHeaderFooter().GetAwaiter().GetResult();
}
private static async Task SetHeaderFooter()
{
    //instantiate PrizmDocServerClient object with Header and footer properties
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    ConversionResult result = await prizmDocServer.ConvertToPdfAsync(
    "myWebPage.html",
    header: new HeaderFooterOptions
        {
            Lines = new List<HeaderFooterLine>
            {
                new HeaderFooterLine { Left = "Page Title", Right = DateTime.Now.ToString() }
            },
        },
    footer: new HeaderFooterOptions
    {
        Lines = new List<HeaderFooterLine>
        {
            new HeaderFooterLine { Right = "Page {{pageNumber}} of {{pageCount}}" },
        },
    });
    //save to the target location
await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
using System.Threading.Tasks;
using System.Collections.Generic;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    SetHeaderFooter().GetAwaiter().GetResult();
}
private static async Task SetHeaderFooter()
{
    //instantiate PrizmDocServerClient object with Header and footer properties
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    ConversionResult result = await prizmDocServer.ConvertToPdfAsync(
    "myWebPage.html",
    header: new HeaderFooterOptions
        {
            Lines = new List<HeaderFooterLine>
            {
                new HeaderFooterLine { Left = "Page Title", Right = DateTime.Now.ToString() }
            },
        },
    footer: new HeaderFooterOptions
    {
        Lines = new List<HeaderFooterLine>
        {
            new HeaderFooterLine { Right = "Page {{pageNumber}} of {{pageCount}}" },
        },
    });
    //save to the target location
await result.RemoteWorkFile.SaveAsync("sample.pdf");
}
Imports System.Threading.Tasks
Imports System.Collections.Generic
Imports Accusoft.PrizmDocServer
Imports Accusoft.PrizmDocServer.Conversion
Shared Sub Main(ByVal args() As String)
	SetHeaderFooter().GetAwaiter().GetResult()
End Sub
Private Shared Async Function SetHeaderFooter() As Task
	'instantiate PrizmDocServerClient object with Header and footer properties
	Dim prizmDocServer = New PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY")
	Dim result As ConversionResult = Await prizmDocServer.ConvertToPdfAsync("myWebPage.html", header:= New HeaderFooterOptions With {.Lines = New List(Of HeaderFooterLine) _
		From {
			New HeaderFooterLine With {
				.Left = "Page Title",
				.Right = DateTime.Now.ToString()
			}
		}
		},
		footer:= New HeaderFooterOptions With {
		.Lines = New List(Of HeaderFooterLine) From {
			New HeaderFooterLine With {.Right = "Page {{pageNumber}} of {{pageCount}}"}
		}
		})
	'save to the target location
Await result.RemoteWorkFile.SaveAsync("sample.pdf")
End Function
VB   C#

輸出:

上述代碼生成的新 PDF 檔案的截圖:

6.3. PDF 頁首和頁尾代碼比較

我們可以看到,相較於 PrizmDoc Viewer,IronPDF 提供了更簡單的編程結構來設置頁首和頁尾屬性。此外,建議使用 IronPDF 生成的 PDF 文件較 PrizmDoc Viewer 生成的文件更具可讀性和吸引力。


7. 將 PDF 頁面轉換為圖像

讓我們再看一個使用案例:我們有一個名為 Sample_PDF.pdf 的簡單 PDF 文件,只有 2 頁。

第一頁頁面2

我們需要創建每頁的圖像。首先,我們將看看如何使用 IronPDF 執行這個任務。

7.1. IronPDF 將 PDF 轉換為圖像

/**
PDF to Image
anchor-ironpdf-convert-pdf-to-image
**/
using IronPdf;
static void Main(string [] args)
{
    //specify file to be converted
    var pdf = PdfDocument.FromFile("Sample_PDF.pdf");
    //save images to the target location
    pdf.RasterizeToImageFiles("image_*.png");
}
/**
PDF to Image
anchor-ironpdf-convert-pdf-to-image
**/
using IronPdf;
static void Main(string [] args)
{
    //specify file to be converted
    var pdf = PdfDocument.FromFile("Sample_PDF.pdf");
    //save images to the target location
    pdf.RasterizeToImageFiles("image_*.png");
}
'''
'''PDF to Image
'''anchor-ironpdf-convert-pdf-to-image
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
	'specify file to be converted
	Dim pdf = PdfDocument.FromFile("Sample_PDF.pdf")
	'save images to the target location
	pdf.RasterizeToImageFiles("image_*.png")
End Sub
VB   C#

輸出:

上述程式碼將會生成以下兩個.png圖像:

頁面1圖片第2頁圖像

我們可以看到使用 IronPDF 創建每個 PDF 頁面的圖像是多麼簡單。現在,我們將使用 PrizmDoc Viewer 執行相同的任務。

7.2. PrizmDoc Viewer PDF 轉換成圖片

using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    PdfToImage().GetAwaiter().GetResult();
}
private static async Task PdfToImage()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //convert PDF file to images
    IEnumerable<ConversionResult> results = await PrizmDocServer.ConvertAsync("Sample_PDF.pdf", DestinationFileFormat.Png);
    //Save each image.
    for (int i = 0; i < results.Count(); i++)
    {
        await results.ElementAt(i).RemoteWorkFile.SaveAsync($"page-{i + 1}.png");
    }
}
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Accusoft.PrizmDocServer;
using Accusoft.PrizmDocServer.Conversion;
static void Main(string [] args)
{
    PdfToImage().GetAwaiter().GetResult();
}
private static async Task PdfToImage()
{
    //instantiate PrizmDocServerClient object
    var prizmDocServer = new PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY");
    //convert PDF file to images
    IEnumerable<ConversionResult> results = await PrizmDocServer.ConvertAsync("Sample_PDF.pdf", DestinationFileFormat.Png);
    //Save each image.
    for (int i = 0; i < results.Count(); i++)
    {
        await results.ElementAt(i).RemoteWorkFile.SaveAsync($"page-{i + 1}.png");
    }
}
Imports System.Linq
Imports System.Collections.Generic
Imports System.Threading.Tasks
Imports Accusoft.PrizmDocServer
Imports Accusoft.PrizmDocServer.Conversion
Shared Sub Main(ByVal args() As String)
	PdfToImage().GetAwaiter().GetResult()
End Sub
Private Shared Async Function PdfToImage() As Task
	'instantiate PrizmDocServerClient object
	Dim prizmDocServer = New PrizmDocServerClient("https://api.accusoft.com", "Your-API-KEY")
	'convert PDF file to images
	Dim results As IEnumerable(Of ConversionResult) = Await PrizmDocServer.ConvertAsync("Sample_PDF.pdf", DestinationFileFormat.Png)
	'Save each image.
	For i As Integer = 0 To results.Count() - 1
		Await results.ElementAt(i).RemoteWorkFile.SaveAsync($"page-{i + 1}.png")
	Next i
End Function
VB   C#

輸出:

上述程式碼還會生成以下兩個 .png 圖片:

第一頁頁面2

7.3. PDF 到影像的程式碼比較

相比 PrizmDoc Viewer,使用 IronPDF 我們可以輕鬆生成每頁的圖像,而且只需要最少的程式碼,甚至不需要遍歷頁面。


8. 許可證價格

在上面的比較中,我們看到了兩個元件的技術工作結構和提供的功能。現在我們將來看看這兩個元件的許可證價格。這是非常重要的,因為我們總是盡力在最低預算下滿足我們的需求。

8.1. IronPDF License Options

IronPDF 授權選項從 $749 開始,適用於單一專案與一位開發人員。

如果您是公司或機構的工程師,並且為多個客戶提供工作,授權起價為 $699,並可根據團隊規模和專案數量進行調整。

以下授權只需一次性支付。

開發人員數量價格
1-5$699
6-10$799
11-20$899
21-50$999
無限制$1,199
  • 對於擁有多個地點的公司,授權費用從 $1199 起。
  • 對於SaaS服務,授權費用從 $1099 起。
  • 對於免版稅的OEM重新分發,授權費用從 $1599 起。

注意: 以上所有授權方案均包括 1年的支援和更新

閱讀更多 關於IronPDF所有提供的授權套餐。

8.2. PrizmDoc Viewer 授權選項

自託管選項

如果您管理自己的伺服器,那麼授權的價格是每年$7,900,並附標準支援。

閱讀更多 關於PrizmDoc Viewer的所有提供的套件資訊。

雲端選項

此授權涵蓋 PrizmDoc Viewer 的雲端服務,該服務按交易數量來擴展。

術語:

交易 意思是我們訪問 PrizmDoc Viewer 伺服器並獲取輸出 (結果文件)Prepaid Buckets是指您只需支付一次並獲得這些不會過期的交易。

交易數量預付包每月每年
200$18
1,000$89
2,000$119
6,000$254$169$1,859(6,000次交易/月)
12,000$434$289$3,179 (12,000 筆交易/月)
25,000`$Lite License``$Lite License`$5,459(25,000 交易/每月)
50,000$1,199$799$8,789(50,000個交易/月)
100,000$1,499$999$10,989 (100,000 筆交易/月)
200,000$2,549$1,699$19,188(200,000 次交易/月)
300,000$3,299$2,199$25,188(300,000 次交易/月)
400,000$4,049$2,699$31,188(400,000 筆交易/月)
500,000$4,799$3,199$37,188(500,000 交易/月)

快速指南

獲取C# IronPDF快速入門手冊

我們創建了一個免費的 PDF 資源指南,以幫助在 .NET 中進行 PDF 開發更容易。此指南包含了常見功能的步驟說明,以及在您的項目中用 C# 和 VB.NET 操作、編輯、生成和保存 PDF 的範例。

下載指南

探索 IronPDF API 參考文獻

探索 IronPDF C# 庫的 API 參考,包括 IronPDF 的所有功能、類別、方法字段、命名空間和枚舉的詳細資料。

查看 API 參考文件
< 上一頁
PDFSharp HTML 轉換PDF範例與教程比較
下一個 >
IronPDF與PDFCrowd之間的比較

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

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