产品比较

Accusoft Prizmdoc PDF 查看器教程和比较

发布 2021年九月2日
分享:

Accusoft PDF Viewer 为 .NET 提供 HTML 转 PDF 功能以及其他 PDF 编辑和处理任务。 IronPDF 还能以编程方式完成这些相同的任务,为您的 C# 项目节省时间和精力。

让我们比较一下这两种方法,看看哪种最适合您的项目。


概述

关于 IronPDF

IronPDF 是一个 C# HTML 转 PDF 库。 它能让工程师完成各种任务,包括从 HTML 字符串、网页、URL 等来源创建 PDF 文件,以及设置水印、书签、页眉和页脚等属性。我们还可以将多个 PDF 文件合并为一个文件,或将 PDF 页面合并为图像,反之亦然。

它可免费用于开发,并提供 30 天的部署试用期,以便您的项目投入使用。

您可以从此处下载文件项目 链接.

关于 Accusoft PrizmDoc Viewer

PrizmDoc 查看器 是一个 REST API,用于处理 PDF 文件并将其远程转换为其他格式。 PrizmDoc 可将 100 多种不同格式的文件转换为 PDF,以及将 PDF 转换为 PNG、JPG、TIFF 和 SVG。 它还可用于在应用程序中加入不同类型的电子签名选项。

对照表

IronPDFPrizmDoc 查看器
以编程方式处理 PDF 文件以编程方式处理 PDF 文件
支持 .NET core,支持 Window、Mac 或 Linux。支持使用 Window、Mac 或 Linux 的 .NET Core。
在当地工作将文档发送到远程服务器。
使用或不使用异步编程。必须使用 `System.Threading.Tasks` 进行异步编程。
在系统中安装 IronPF 后,可轻松实现离线工作。Must connect with the internet to send the request to the PrizmDoc 查看器 server (Cloud-hosted or self-hosted).
提供许多预定义功能。提供一些预定义功能。
通常只需最少的代码行。通常需要许多行代码。
每个许可证计划中的每个项目可进行无限次转换。每个云托管许可计划的交易次数有限。
免费开发,无时间限制。试用期内仅有 300 笔交易。

让我们安装这两个软件并比较一下代码。


步骤 1:安装

1.安装 IronPDF 库

在您的项目中安装 IronPDF 有两种方法,您采用哪种并无区别。

1.1.下载 IronPDF DLL

下载 IronPDF.dll 并将其引用添加到项目中。 之后,你可以通过以下方式轻松访问命名空间 IronPDF

使用 IronPDF;``

现在,您可以轻松访问 IronPDF 提供的函数和类。

1.2 通过 NuGet 软件包管理器安装

  • 软件包管理器控制台:

     如果您使用的是软件包管理器控制台,请运行以下命令:
    :ProductInstall
  • 管理解决方案软件包:

     如果您使用的是 [NuGet 软件包管理器](https://www.nuget.org/packages/IronPdf)然后在搜索栏中浏览 "IronPDF "并安装。

    从 Accusoft 安装 PrizmDoc Viewer

    PrizmDoc Viewer 有两个部分,一个是名为 "PrizmDoc Server "的服务器端,它的行为就像一个 Restful API。 另一个是我们的项目,通过这个项目,我们点击应用程序接口并获取响应。

    访问 PrizmDoc 服务器

    正如我们从其名称中看到的,它是一个服务器端应用程序,通过请求获取文档的基本信息 (输入) 并将文档转换为 PDF 文件,然后将转换后的 PDF 文件作为响应发送给客户端 (产量). 它是产品的技术核心,是一个文档处理和转换引擎。我们可以通过两种不同的方式使用它,采用哪种方式并无区别,因为两者具有相同的编程结构和技术:

  1. 自我托管:

    对于此选项,您需要安排您的服务器,您可以 [下载 PrizmDoc 服务器](https://www.accusoft.com/products/prizmdoc-suite/prizmdoc-viewer-trial/) 然后安装。[了解更多](https://help.accusoft.com/PrizmDoc/v13.14/HTML/install-on-windows.html) 了解如何在 Windows 上安装 PrizmDoc Server。
    
    **注意:** 它至少需要 32GB 内存和 4 核 CPU,否则会带来糟糕的体验。
  2. 云托管:

    它是 PrizmDoc Viewer 基于云的服务,您无需安排服务器。 我们将用它来进行比较。 要做到这一点 [创建账户](https://cloud.accusoft.com/signup) 然后主页就会打开。 您可以从 "API 密钥 "菜单中复制 "API 密钥",稍后我们将了解如何使用它。

    首先,我们将看到如何使用 PrizmDoc Viewer 将文档转换为 PDF 文件的基本结构,然后我们将使用 "WebClient "直接与 "Accusoft 服务器 "交互。()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);
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

上述示例需要付出大量努力! 为尽量减少工作量,Accusoft 引入了一个名为.NET 的库。 Accusoft.PrizmDocServerSDK它是 PrizmDoc 服务器 REST API 的封装。 让我们看看如何在 .NET 项目中安装和使用该库

安装 Accusoft.PrizmDocServerSDK

有两种安装包装器的方法。

  • 软件包管理器控制台:

     如果您使用的是软件包管理器控制台,请运行以下命令:
    :InstallCmd install-package Accusoft.PrizmDocServerSDK
  • 管理解决方案软件包:

     如果使用的是 NuGet 软件包管理器的图形用户界面,则在搜索栏中浏览 "Accusoft.PrizmDocServerSDK "并安装。

    现在,您可以轻松访问 "Accusoft.PrizmDocServer "命名空间,并通过访问来使用它:

    使用 Accusoft.PrizmDocServer;``


    教程

2.IronPDF 与 PrizmDoc 浏览器代码比较

在阅读了两个组件的介绍和安装之后,现在是使用这两个组件的时候了。 为此,我们将选取一些使用案例,并使用这两个组件来实现它们。 我们希望这能让您轻松了解这两种编程结构,并得出哪种结构最适合您的项目。


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 转 PDF

在安装 PrizmDoc Viewer 时,我们已经讨论了如何获取 "Accusoft API 密钥",现在我们来看看如何使用它。

首先,我们向 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

在本比较中,我们以需要通过 图像它存在于项目的 debug 文件夹中。 让我们从 IronPDF 开始。

4.1.IronPDF Image to 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 只需编写 2 行简单的代码。 另一方面,在使用 PrizmDoc 服务器时,我们必须编写许多行异步编程代码。 IronPDF 的输出还能自动提供可用的全页文档。


5.合并 PDF 文件

在这次比较中,假设我们有三个 PDF 文件,分别命名为 A.pdfB.pdfC.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();
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

上述代码将创建一个由 A.pdfB.pdfC.pdf 组合而成的 sample.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");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
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 用于指定页眉或页脚的字体大小。
  • 间距 它调整页面内容与页眉或页脚之间的间距。

    以下一些预定义属性对设置页眉或页脚内容很有帮助。 可以写在大括号 中。{ }如下:

  • {页码} 在页眉或页脚打印当前页码。
  • {总页数} 打印页眉或页脚中的总页数。
  • {网址} 用于打印渲染页面的 URL。
  • {日期} 在页眉或页脚打印当前日期。
  • {时间} 在页眉或页脚打印当前时间。
  • {html-title} 在页眉或页脚打印已渲染网页的标题
  • {pdf标题} 在页眉或页脚打印文档标题。

    了解更多 详细介绍如何使用 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 "类来处理页眉和页脚,并具有以下属性:

  • 指定行(s) 用于页眉和页脚(当你理解了下面的例子,就会更加清楚),每一行都具有以下特性:
    • 打印页眉或页脚行左侧的文本。
    • *中心****打印页眉或页脚行左侧的文本。
    • *右****打印页眉或页脚行右侧的文本。
  • FontFamily 用于指定页眉或页脚文本的字体系列。
  • FontSize 用于指定页眉或页脚文本的字体大小。
  • *颜色***用于指定页眉或页脚文本的颜色。

    了解更多 了解如何使用 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 页眉和页脚代码比较

我们可以看到,IronPDF 与 PrizmDoc Viewer 相比,通过简单的编程结构提供了更多的功能来设置页眉和页脚属性。 还有人提出,IronPDF 生成的 PDF 文件比 PrizmDoc Viewer 生成的文件更具可读性和吸引力。


7.将 PDF 页面转换为图像

让我们再看一个用例:我们有一个名为 Sample_PDF.pdf 的简单 PDF 文件,只有 2 页。

第1页第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 图像:

第1页第2页

7.3.PDF 转图像代码比较

与 PrizmDoc Viewer 相比,使用 IronPDF,即使不对页面进行迭代,我们也能用最少的代码行轻松创建每个页面的图像。


8.许可证定价

从上述对比中,我们可以看到两个组件的技术工作结构和提供的功能。 现在我们来看看这两个组件的许可证定价。 这一点非常重要,因为我们总是尽力用最少的预算来满足我们的要求。

8.1.IronPDF 许可证选项

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 基于云的服务,该服务根据交易数量进行扩展。

术语:

Transaction "表示我们访问 PrizmDoc Viewer 服务器并获取输出结果 (成果文件).

预付桶 " 意味着您只需支付一次,即可获得交易,且不会过期。

交易数量预付费桶每月每年
200$18
1,000$89
2,000$119
6,000$254$1691,859 美元(每月 6,000 笔交易)
12,000$434$2893,179 美元(每月 12,000 笔交易)
25,000$liteLicense$liteLicense5 459 美元(每月 25 000 笔交易)
50,000$1,199$7998 789 美元(每月 50 000 笔交易)
100,000$1,499$99910 989 美元(每月 100 000 笔交易)
200,000$2,549$1,69919 188 美元(每月 200 000 笔交易)
300,000$3,299$2,19925 188 美元(每月 300 000 笔交易
400,000$4,049$2,69931 188 美元(每月 400 000 笔交易)
500,000$4,799$3,19937 188 美元(每月 500 000 笔交易)

教程快速访问

获取 C# IronPDF 快速入门手册

我们创建了一个免费的 PDF 资源指南,以帮助您更轻松地为 .NET 开发 PDF,其中包括常用函数的演练以及在 C# 和 VB.NET 项目中操作、编辑、生成和保存 PDFS 的示例。

下载指南

探索 IronPDF API 参考

探索 IronPDF C# 库的 API 参考,包括 IronPDF 的所有功能、类、方法字段、命名空间和枚举的详细信息。

查看应用程序接口参考
< 前一页
PDFSharp HTML 到 PDF 示例和教程比较
下一步 >
IronPDF与PDFCrowd的比较

准备开始了吗? 版本: 2024.9 刚刚发布

免费NuGet下载 总下载量: 10,731,156 查看许可证 >