在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
Accusoft PDF Viewer 提供 HTML 到 PDF 的功能以及其他 PDF 編輯和操作任務,適用於 .NET。 IronPDF 也能以程式方式完成這些相同的任務,為您的 C# 專案節省時間和精力。
讓我們比較這兩者,找出最適合您的專案的選擇。
IronPDF 是一個 C# HTML 到 PDF 的程式庫。 它使工程師能夠執行的任務包括從 HTML 字串、網頁、URL 等來源創建 PDF 文件,以及設置水印、書籤、頁眉和頁腳等屬性。我們也可以將多個 PDF 文件合併為一個,或將 PDF 頁面轉換為圖像,反之亦然。
它可免費用於開發,並提供 30 天的部署試用期以使您的專案上線。
您可以從此鏈結下載文件專案。
PrizmDoc Viewer 是一個 REST API,用於處理 PDF 文件並將其遠程轉換為其他格式。 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 套件管理員的 GUI,請在搜索欄瀏覽IronPDF
並安裝它。
PrizmDoc Viewer 有兩個部分,一個是稱為PrizmDoc Server
的伺服器端,其作為一個 Restful API 運作。 另一個是我們的專案,我們通過這個專案調用 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撰寫兩行簡單的程式碼。 另一方面,使用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 文件,並設置以下頁首和頁尾屬性:
Page Title
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
類,處理頁首和頁尾,具有以下屬性:
行 指定頁首和頁尾的行數(理解以下範例後會更清晰),每行具有以下屬性:
左將文本打印在頁眉或頁腳行的左側。
顏色來指定頁眉或頁腳文字的顏色。
閱讀更多關於如何使用 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 操作、編輯、生成和保存 PDF 的範例。
下載指南