在生产环境中测试,无水印。
随时随地满足您的需求。
获得30天的全功能产品。
几分钟内就能启动并运行。
在您的产品试用期间,全面访问我们的支持工程团队。
Accusoft PDF Viewer 为 .NET 提供 HTML 转 PDF 功能以及其他 PDF 编辑和处理任务。 IronPDF 还能以编程方式完成这些相同的任务,为您的 C# 项目节省时间和精力。
让我们比较一下这两种方法,看看哪种最适合您的项目。
IronPDF 是一个 C# HTML 转 PDF 库。 它能让工程师完成各种任务,包括从 HTML 字符串、网页、URL 等来源创建 PDF 文件,以及设置水印、书签、页眉和页脚等属性。我们还可以将多个 PDF 文件合并为一个文件,或将 PDF 页面合并为图像,反之亦然。
它可免费用于开发,并提供 30 天的部署试用期,以便您的项目投入使用。
您可以通过此链接下载一个文件项目。
PrizmDoc Viewer 是一个用于远程处理PDF文件并将其转换为其他格式的REST API。 PrizmDoc 可将 100 多种不同格式的文件转换为 PDF,以及将 PDF 转换为 PNG、JPG、TIFF 和 SVG。 它还可用于在应用程序中加入不同类型的电子签名选项。
IronPDF | PrizmDoc Viewer |
---|---|
Work with PDF files programmatically. | Work with PDF files programmatically. |
Supports .NET core with Window, Mac, or Linux. | Supports .NET Core using Window, Mac, or Linux. |
Works Locally | Sends Documents to a remote server. |
Work with or without using Asynchronous Programming. | Must use Asynchronous Programming using `System.Threading.Tasks`. |
Easily work offline once we install IronPF in our system. | Must connect with the internet to send the request to the PrizmDoc Viewer server (Cloud-hosted or self-hosted). |
Provides many predefined functions. | Provides some predefined functions. |
Often requires minimal lines of code. | Often requires many lines of code. |
Unlimited conversions per project in each license plan. | Limited number of transactions in each cloud-hosted license plan. |
Free for development with no time limit. | Only 300 transactions with trial. |
让我们安装这两个软件并比较一下代码。
在您的项目中安装 IronPDF 有两种方法,您采用哪种并无区别。
下载 IronPDF.dll 并将其引用添加到您的项目中。 之后,您可以通过以下方式轻松访问命名空间IronPdf
:
using IronPdf;
现在,您可以轻松访问 IronPDF 提供的函数和类。
软件包管理器控制台:
如果您使用的是软件包管理器控制台,请运行以下命令:
:ProductInstall
管理解决方案软件包:
如果您正在使用NuGet Package Manager的GUI,那么在搜索栏中浏览IronPDF
并安装它。
PrizmDoc Viewer 有两个部分,一个是服务器端,称为 PrizmDoc Server
,它表现为一个 Restful API。 另一个是我们的项目,通过这个项目,我们点击应用程序接口并获取响应。
正如我们从其名称中看到的,这是一个服务器端应用程序,它通过文档作为请求(输入)获取基本信息,并将文档转换为PDF文件,然后将转换后的PDF文件作为响应(输出)发送给客户端。 它是产品的技术核心,是一个文档处理和转换引擎。我们可以通过两种不同的方式使用它,采用哪种方式并无区别,因为两者具有相同的编程结构和技术:
自托管:
对于此选项,您需要安排您的服务器,您可以下载 PrizmDoc Server并进行安装。了解更多有关如何在 Windows 上安装 PrizmDoc Server 的信息。
注意:它至少需要32 GB的内存和4核CPU,否则,您可能会面临不佳的体验。
云托管:
这是一个基于云的PrizmDoc Viewer服务,您无需安排服务器。 我们将用它来进行比较。 要执行此操作,创建您的帐户,然后主页将会打开。 您可以从API Key
菜单中复制API key
,稍后我们将看到如何使用它。
首先,我们将看到如何使用 PrizmDoc Viewer 将文档转换为 PDF 文件的基本结构,并且我们将在 C# 控制台应用程序中使用 WebClient()
直接与 Accusoft server
进行交互。
注意:以下示例仅用于帮助理解PrizmDoc如何处理PDF文件。 这有点长,所以如果您跳过这个示例并直接进入比较,也没有问题。
在这个例子中,我们将把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
然后创建一个公共变量Accusoft API Key
,并按如下所示粘贴您的API密钥:
static string ApiKey= "Your-API-KEY";
static string ApiKey= "Your-API-KEY";
IRON VB CONVERTER ERROR developers@ironsoftware.com
使用 PrizmDoc Viewer 处理 PDF 文件有 3 个步骤:
向 PrizmDoc 服务器上传文件。
转换上传的文件。
从 PrizmDoc 服务器下载转换后的文件。
因此,我们将为每个步骤创建一个单独的函数。
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();
}
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();
}
Shared Sub Main(ByVal args() As String)
'---Upload file to Server---
Dim uploadResults As JObject = UploadToServer("myWebpage.html").Result
Dim fileID As String = CStr(uploadResults.SelectToken("fileId"))
Dim affinityToken As String = CStr(uploadResults.SelectToken("affinityToken"))
'---Convert the uploaded file to PDF---
Dim convertResults As JObject = Convert(affinityToken, fileID).Result
Dim processId As String = CStr(convertResults.SelectToken("processId"))
affinityToken = CStr(convertResults.SelectToken("affinityToken"))
'---Check the status that conversion is completed---
Dim convertStatusresults As JObject = ConvertStatus(processId, affinityToken).Result
Dim convertStatus As String = CStr(convertResults.SelectToken("state"))
'---Continuously checking whether conversion completed or not until completed---
Do While Not (convertStatus.Equals("complete"))
System.Threading.Thread.Sleep(30000)
convertStatusresults = ConvertStatus(processId, affinityToken).Result
convertStatus = CStr(convertStatusresults.SelectToken("state"))
Loop
'---Download the converted file from server---
Dim newFileID As String = CStr(convertStatusresults.SelectToken("output.results [0].fileId"))
DownloadFromServer(affinityToken, newFileID, "sample.pdf").Wait()
Console.WriteLine("PDF file created successfully...!")
Console.ReadKey()
End Sub
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
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
以下 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
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
上述示例需要付出很多努力! 为了减少工作量,Accusoft 引入了一个名为 Accusoft.PrizmDocServerSDK 的 .NET 库,它是 PrizmDoc Server REST API 的包装。 让我们看看如何在 .NET 项目中安装和使用该库
有两种安装包装器的方法。
软件包管理器控制台:
如果您使用的是软件包管理器控制台,请运行以下命令:
:InstallCmd install-package Accusoft.PrizmDocServerSDK
管理解决方案软件包:
如果您正在使用 NuGet 包管理器的 GUI,请在搜索栏中浏览 Accusoft.PrizmDocServerSDK
并安装它。
现在,您可以轻松访问Accusoft.PrizmDocServer
命名空间,并通过以下方式使用:
using Accusoft.PrizmDocServer;
在阅读了两个组件的介绍和安装之后,现在是使用这两个组件的时候了。 为此,我们将选取一些使用案例,并使用这两个组件来实现它们。 我们希望这能让您轻松了解这两种编程结构,并得出哪种结构最适合您的项目。
在我们的第一次比较中,假设我们有一个名为myWebPage.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
上述代码将创建一个sample.pdf
文件并保存到项目的bin>debug
文件夹中。
您也可以指定如下路径:PDF.SaveAs("E:/sample.pdf");
阅读更多关于如何使用IronPDF处理PDF文件。
现在,我们将使用 PrizmDoc Viewer 完成同样的任务,这样我们就可以轻松地进行比较了。
在 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
了解更多 关于如何使用 PrizmDoc Viewer。
从这些例子中我们可以看出,IronPDF 是一种比较简单的创建 PDF 文件的方法,不需要花费那么多时间。
在此比较中,我们采用一个用例,即需要通过图像创建一个PDF文件,该图像位于项目的debug
文件夹中。 让我们从 IronPDF 开始。
/**
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
输出:
此屏幕截图是使用上述代码新创建的 PDF 文件sample.pdf
。
我们可以看到,使用 IronPDF 从图像创建 PDF 文件是多么容易。 现在,我们将使用 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
输出:此屏幕截图是通过上述代码新创建的 PDF 文件 sample.pdf
:
我们可以看到,使用 IronPDF 只需编写 2 行简单的代码。 另一方面,在使用 PrizmDoc 服务器时,我们必须编写许多行异步编程代码。 IronPDF 的输出还能自动提供可用的全页文档。
在这个比较中,假设我们有三个名为A.pdf
、B.pdf
和C.pdf
的PDF文件。 我们希望将它们合并成一个 PDF 文件,而我们可以使用这两个组件来完成这项任务。 首先,我们来看看如何使用 IronPDF 执行这项任务。
/**
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
上述代码将创建一个sample.pdf
文件,这是A.pdf
、B.pdf
和C.pdf
的组合。
现在,我们将使用 PrizmDoc Viewer 完成同样的任务。
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
上述代码还将创建一个sample.pdf
文件,该文件是A.pdf
、B.pdf
和C.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>
我们要将此网页转换为 PDF 文件,设置以下页眉和页脚属性:
页面标题
DateTime
页码 总页数 在页脚的右侧。
首先,我们来看看如何使用 IronPDF 设置页眉和页脚。
为处理PDF文件的页眉和页脚,IronPDF在ChromePdfRenderer
类上提供了一个名为RenderingOptions
的属性,可以这样使用:
头条新闻
C# ChromePdfRenderer_Obj.RenderingOptions.TextHeader=new TextHeaderFooter()
对于页脚:
C# ChromePdfRenderer_Obj.RenderingOptions.TextFooter=new TextHeaderFooter()
我们可以在初始化TextHeaderFooter()
时设置以下属性:
间距 它调整页面内容与页眉或页脚之间的空间。
以下一些预定义属性对设置页眉或页脚内容很有帮助。 它可以写在花括号 { }
中,如下所示:
{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
输出: 通过上述代码新创建的 PDF 文件 sample.pdf
的截图:
我们可以看到,在使用 IronPDF 创建 PDF 文件时,使用直观的语言处理页眉和页脚是多么简单。 现在,我们来看看如何使用 PrizmDoc Viewer 设置页眉和页脚。
PrizmDoc Viewer 提供 HeaderFooterOptions
类以处理页眉和页脚,具有以下属性:
行 它指定页眉和页脚的行(在理解以下示例时会更清晰),每行具有以下属性:
Left 在页眉或页脚线的左侧打印文本。
颜色 用于指定页眉或页脚文字的颜色。
了解更多关于如何使用 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
输出:
通过上述代码新建 PDF 文件的截图:
我们可以看到,IronPDF 与 PrizmDoc Viewer 相比,通过简单的编程结构提供了更多的功能来设置页眉和页脚属性。 还有人提出,IronPDF 生成的 PDF 文件比 PrizmDoc Viewer 生成的文件更具可读性和吸引力。
让我们再看一个使用案例:我们有一个名为Sample_PDF.pdf
的简单PDF文件,只有2页。
我们需要为每个页面创建一个图像。 首先,我们来看看如何使用 IronPDF 执行这项任务。
/**
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
输出:
上述代码将创建以下两个.png
图像:
我们可以看到,使用 IronPDF 创建每个 PDF 页面的图像是多么简单。 现在,我们将使用 PrizmDoc Viewer 完成同样的任务。
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
输出:
上述代码还将创建以下两个.png
图像:
与 PrizmDoc Viewer 相比,使用 IronPDF,即使不对页面进行迭代,我们也能用最少的代码行轻松创建每个页面的图像。
从上述对比中,我们可以看到两个组件的技术工作结构和提供的功能。 现在我们来看看这两个组件的许可证定价。 这一点非常重要,因为我们总是尽力用最少的预算来满足我们的要求。
IronPDF 许可证的起价为$749,适用于单个项目和一位开发人员。
如果你是一家公司或机构的工程师,为多个客户提供服务,许可证起价为 699 美元,可根据团队规模和项目数量进行调整。
以下许可证只需一次性付款。
Number of Developers | Price |
---|---|
1-5 | $699 |
6-10 | $799 |
11-20 | $899 |
21-50 | $999 |
Unlimited | $1,199 |
对于免版税的OEM重新分发,许可证价格从$1599起。
注意:所有上述许可包均包含1年支持与更新。
阅读更多关于IronPDF提供的所有授权包。
如果您管理自己的服务器,则许可证的价格为$7,900/年,包含标准支持。
阅读更多关于PrizmDoc Viewer所有提供的套餐信息。
该许可证用于 PrizmDoc Viewer 基于云的服务,该服务根据交易数量进行扩展。
术语:
Transaction
指的是我们访问PrizmDoc Viewer服务器并获取输出(结果文档)。
Prepaid Buckets
意味着您一次性支付费用,然后获取不会过期的交易。
No of Transactions | Prepaid Buckets | Monthly | Annually |
---|---|---|---|
200 | $18 | ||
1,000 | $89 | ||
2,000 | $119 | ||
6,000 | $254 | $169 | $1,859 (6,000 Transactions/Month) |
12,000 | $434 | $289 | $3,179 (12,000 Transactions/Month) |
25,000 | $749 | $749 | $5,459 (25,000 Transactions/Month) |
50,000 | $1,199 | $799 | $8,789 (50,000 Transactions/Month) |
100,000 | $1,499 | $999 | $10,989 (100,000 Transactions/Month) |
200,000 | $2,549 | $1,699 | $19,188 (200,000 Transactions/Month) |
300,000 | $3,299 | $2,199 | $25,188 (300,000 Transactions/Month |
400,000 | $4,049 | $2,699 | $31,188 (400,000 Transactions/Month) |
500,000 | $4,799 | $3,199 | $37,188 (500,000 Transactions/Month) |
我们创建了一个免费的 PDF 资源指南,以帮助您更轻松地为 .NET 开发 PDF,其中包括常用函数的演练以及在 C# 和 VB.NET 项目中操作、编辑、生成和保存 PDFS 的示例。
下载指南