產品比較

IronPDF與PDFCrowd之間的比較

發佈 2021年12月13日
分享:

IronPDF 和 PDFCrowd - 全面比較

隨著技術的不斷進步,每個人,尤其是開發人員,能夠使用更智能的解決方案來節省時間。自動化現在已成為軟體開發過程中的關鍵。在 C# 中處理 PDF 文件多年來一直困擾著開發人員。從 PDF 文件中呈現內容時需要考慮多種因素,特別是在將不同格式的內容轉換為 PDF 時問題更加複雜。隨著眾多旨在從不同格式讀取、寫入、創建和轉換為 PDF 的庫的完成,這些問題現在得以解決。

本文將比較兩個最受 .NET 和 .NET Core 開發人員歡迎的 PDF 庫。這兩個庫是:

  • IronPDF
  • PDFCrowd

IronPDF 和 PDFCrowd 都是提供創建、操作和 列印 PDF 在 .NET 和 .NET Core 中。下一個問題是決定哪個 C# PDF函式庫 最適合你的 .NET 專案嗎?你可以在閱讀以下兩個庫及其各自突出的 PDF 轉換和操作功能比較時,權衡你的決定。

讓我們先看看兩個庫都提供了什麼,然後再進行比較。

IronPDF 及其主要功能

IronPDF .NET PDF 庫解決方案是開發人員的夢想,尤其是使用 C# 的軟體工程師。你可以使用這個優秀的工具輕鬆地為 .NET 建立核心 PDF 庫。

IronPDF 使用 .NET Chromium 引擎將 HTML 頁面渲染成 PDF 文件。使用 HTML 轉 PDF 功能,不需要使用複雜的 API 來定位或設計 PDF。IronPDF 支援標準的網頁文件:HTML、ASPX、JS、CSS 和圖像。

它還讓你能夠使用 HTML5、CSS、JavaScript 和圖像創建 .NET PDF 庫。你可以輕鬆地編輯、加蓋印章以及添加標頭和頁腳到 PDF 文件。此外,它使這些操作變得非常容易。 讀取 PDF 文字與提取圖像。

The IronPDF C# Library - 突出功能

一些重要功能包括:

創建PDF (HTML 轉 PDF)

  • 從 HTML 4 和 5、CSS 以及 JavaScript 創建 PDF 文件
  • 從 URL 生成 PDF 文件
  • 使用自訂的網絡登錄憑證、User-Agents、代理、Cookie、HTTP 標頭、表單變量來加載 URL,允許通過 HTML 登錄表單進行登錄

在不使用 Adobe Acrobat 的情況下編輯現有 PDF 文件

  • 閱讀和填充表單字段數據
  • 從 PDF 中提取圖像和文本
  • 將新 HTML 內容蓋印到任何現有的 PDF 頁面上
  • 添加邏輯或 HTML 標題和頁腳

操作現有 PDF 文檔

  • 加載和解析現有的 PDF 文件
  • 合併和拆分 PDF 文件中的內容
  • 添加標題、頁腳、註釋、書籤、水印、文本和圖像資產

多種格式轉換

  • ASPX WebForms – 只需 3 行代碼,將 ASP.NET webforms 轉換為可在瀏覽器中查看的可下載 PDF
  • HTML 文件 – 將 HTML 轉換為 PDF
  • 自訂“基礎 URL”,允許跨網絡訪問資產文件
  • 通過虛擬視口實現響應布局 (寬度和高度)
  • 接受任何主要文件編碼中的HTML編碼 (預設為UTF-8)

保存和列印

  • 從檔案、二進位數據或MemoryStreams中保存和載入
  • 螢幕或列印的CSS媒體類型
  • 將 PDF 檔案轉換為 PrintDocument 物件,無需 Adobe 即可列印 (使用最少的代碼)
  • 匯出包含 API 成功與原始碼調試錯誤詳細資訊的正式日誌文件

The PDFCrowd Library - 突出功能

Pdfcrowd.com API 是一個專業解決方案,用於從網頁和 HTML 文件創建 PDF 和截圖圖像。這是一個在線網絡服務,允許您將任何網頁轉換為 PDF。API 是一個網絡服務,您的輸入會在 PDFCrowd 伺服器上進行轉換。

它高質量且快速,從而為您節省時間。它安全且具有壓縮文件的能力。

PDFCrowd API 功能

以下是一些最重要的 PDFCrowd 功能:

HTML 到 PDF API

  • 易於使用的 API 客戶端 SDK 庫
  • 支援最新的網頁標準
  • 集成僅需幾分鐘即可設置,無需第三方庫
  • 幾乎可在任何平台上使用 - Windows、Linux、macOS、BSD、類 Unix 系統等
  • 可靠、廣泛可用,並支持最新的 HTML5、CSS3 和 JavaScript 規範

API 操作台

  • 互動式探索 API 設定
  • PDF 預覽、自動代碼生成
  • 轉換網頁、HTML 文件或 HTML 代碼

注意: PDFCrowd 不提供可離線使用的獨立 SDK。

本文的其餘部分將探討以下主題:

  1. 創建一個項目
  2. IronPDF C# 庫安裝
  3. PDFCrowd API 安裝
  4. 從現有的 URL 創建 PDF
  5. 從 HTML 輸入字符串創建 PDF
  6. 將 ASPX 頁面轉換為 PDF
  7. 將 XML 轉換為 PDF
  8. 將圖像轉換為 PDF
  9. 授權
  10. 摘要與結論

1. 創建 ASP.NET 專案

使用以下步驟來創建 ASP.NET 網站:

  • 打開 Visual Studio 2019
  • 從選單中點擊【檔案】,然後點擊【新專案】來創建一個新專案
  • 在專案類型列表框中選擇 Visual C# 下的【Web】
  • 選擇 【ASP.NET Web 應用程序】 (.NET框架) 按下圖所示點擊「確定」

圖 1新專案對話框

  • 在下一個畫面中,選擇「Web Forms」,如下面的截圖所示。

圖2網頁表單

  • 一旦全部選擇完畢,點擊確定。

現在專案已經建立,我們幾乎準備好測試這些庫了。不過,我們仍需安裝並將它們整合到我們的專案中。讓我們先安裝 IronPDF。

2. IronPDF C# 程式庫安裝

有四種方式可以下載和安裝 IronPDF 程式庫。它們如下:

  1. 使用 Visual Studio
  2. 開發者命令提示符
  3. 直接下載 NuGet 套件
  4. 下載 IronPDF .DLL 程式庫

讓我們仔細看看每一種方法。

2.1 使用 Visual Studio

Visual Studio 提供了 NuGet 套件管理器來安裝你的專案所需的 NuGet 套件。你可以透過專案選單或在方案總管中右鍵點擊你的專案來訪問它。這些選項在下面的螢幕截圖中分別顯示為圖 3 和圖 4。

圖3專案選單 > 管理 NuGet 套件

圖4右鍵解決方案總管

選定後,瀏覽 IronPDF 套件並安裝,如下圖所示。

圖 5從 NuGet 套件安裝 IronPDF

2.2 使用開發者命令提示字元

另一種下載和安裝 IronPDF C# 函式庫的方法是通過以下步驟,通過開發者命令提示字元安裝 IronPDF NuGet 套件

  • 打開 開發者命令提示字元 – 通常位於 Visual Studio 文件夾下
  • 鍵入以下命令:
  :ProductInstall
  • 按下 Enter 鍵
  • 這將下載並安裝套件
  • 重新載入您的 Visual Studio 專案並開始使用

2.3. 直接下載 NuGet 套件

第三種下載和安裝 IronPDF 的方法是按照以下步驟操作。這可以通過直接訪問 NuGet 網站並下載套件來完成。步驟如下:

2.4. 透過下載庫來安裝 IronPDF

您可以直接從網站下載 IronPDF .DLL 文件。可以直接從 IronPDF DLL下載.

圖6直接下載 IronPDF C# 庫

在專案中參考庫的步驟如下:

  • 在方案總管中右鍵點選方案
  • 選擇參考
  • 瀏覽 IronPDF.dll 庫
  • 點擊確定

全部完成! IronPDF 已下載、安裝並準備好使用。然而,在此之前我們應該安裝 PDFCrowd API。

3.PDFCrowd API 安裝

身份驗證

為了使用 Pdfcrowd API 客戶端,需要進行身份驗證。您訪問 API 所使用的憑據是您的 Pdfcrowd 用戶名和 API 密鑰。

Pdfcrowd API 客戶端庫適用於 .NET

Pdfcrowd API 客戶端庫允許您在 HTML、PDF 和各種圖像格式之間進行轉換。該 .NET API 客戶端庫使實現變得簡單 Pdfcrowd API 在你的 .NET 應用程式中。

可以通過以下三種方式安裝 PDFCrowd API Client Library for .NET:

  1. 直接下載 Pdfcrowd 客戶端作為 Zip 檔案

  2. 通過 NuGet Package Manager 安裝Pdfcrowd 官方客戶端套件

  3. 通過 Pdfcrowd GitHub 儲存庫

讓我們仔細看看每一種安裝方法。

3.1 直接下載

下載 pdfcrowd-5.2.0-dotnet.zip,解壓縮並將 pdfcrowd.dll 添加到您的項目中。

在您的項目中引用庫,請按照以下步驟操作:

  • 在解決方案資源管理器中右鍵單擊解決方案
  • 選擇引用
  • 瀏覽查找 pdfcrowd.dll 庫
  • 點擊確定

3.2 從開發者命令提示字元使用 NuGet 套件管理員

另一種下載和安裝 PDFCrowd API 的方式是使用下面的步驟,透過開發者命令提示字元安裝 PDFCrowd API Client NuGet 套件

  • 開啟 開發者命令提示字元 – 通常在 Visual Studio 資料夾底下找到
  • 輸入以下命令: PM > Install-Package Pdfcrowd.official -Version 5.2.0
  • 按下 Enter 鍵
  • 這將會下載並安裝套件
  • 重新載入你的 Visual Studio 專案並開始使用

3.3 GitHub 儲存庫

要安裝 PDFCrowd,您可以克隆 pdfcrowd-dotnet 從 Github 下載並構建該庫。此客戶端庫是根據 MIT 授權許可證授權的。

使用以下命令來構建 PDFCrowd API 客戶端庫:

  • git clone https://github.com/pdfcrowd/pdfcrowd-dotnet
  • cd pdfcrowd-dotnet
  • make.bat # 在 Windows 上
  • make all # 在 Unix 上

現在我們已經創建了項目並安裝了必要的庫,讓我們開始在代碼層面上比較 IronPDF 和 PDFCrowd 庫。

4. 從現有的URL創建PDF

這兩個庫都提供了將HTML網頁轉換為PDF的功能。我們逐一查看每個庫的代碼。

4.1. 使用 IronPDF 將現有的網址轉換為 PDF

IronPDF 使從現有的網址渲染 HTML 為 PDF 文件變得非常簡單。對 JavaScript、圖像、表單和 CSS 的支持非常高。

以下代碼使用 IronPDF 直接從網站地址創建一個 PDF 文件。

IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

Pdf.SaveAs("url.pdf");
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

Pdf.SaveAs("url.pdf");
Dim Renderer As New IronPdf.ChromePdfRenderer()
Dim Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")

Pdf.SaveAs("url.pdf")
VB   C#

4.2 使用 PDFCrowd 將現有 URL 轉換成 PDF

使用 PDFCrowd 將 URL 轉換成 PDF 文件也非常簡單。以下代碼使用 PDFCrowd 從網站地址直接生成 PDF 文件。

// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and write the result to a file
client.convertUrlToFile("http://www.pdfcrowd.com", "example.pdf");
// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and write the result to a file
client.convertUrlToFile("http://www.pdfcrowd.com", "example.pdf");
' create the API client instance
Dim client As New pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d")

' run the conversion and write the result to a file
client.convertUrlToFile("http://www.pdfcrowd.com", "example.pdf")
VB   C#

5. 從 HTML 輸入字串創建 PDF

IronPDF 和 PDFCrowd 都提供從包含 HTML 的字串生成 PDF 的功能。兩者都只需要兩行代碼就能完成這項任務。

5.1. 使用 IronPDF 的 HTML 輸入字串

以下代碼顯示了如何使用 HTML 輸入字串來渲染 PDF 文件。您可以選擇簡單的 HTML,或者同時結合 CSS、圖片和 JavaScript。

var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");

// Load external html assets: images, css and javascript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from 
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");

// Load external html assets: images, css and javascript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from 
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>")
PDF.SaveAs("pixel-perfect.pdf")

' Load external html assets: images, css and javascript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from 
Dim AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
AdvancedPDF.SaveAs("html-with-assets.pdf")
VB   C#

5.2. 使用 PDFCrowd 的 HTML 輸入字符串

以下代碼顯示了如何使用包含 HTML 的字符串來生成 PDF 文件。HTML 輸入字符串還可以用於轉換為內存中的 PDF,並將生成的 PDF 寫入輸出流。

// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and write the result to a file
client.convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf");

// run the conversion and store the result into the "pdf" variable
byte [] pdf = client.convertString("<html><body><h1>Hello World!</h1></body></html>");
// at this point the "pdf" variable contains PDF raw data and
// can be sent in an HTTP response, saved to a file, etc.

// create an output stream for the conversion result
FileStream outputStream = new FileStream("HelloWorld.pdf", FileMode.CreateNew);

// run the conversion and write the result into the output stream
client.convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", outputStream);

// close the output stream
outputStream.Close();
// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and write the result to a file
client.convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf");

// run the conversion and store the result into the "pdf" variable
byte [] pdf = client.convertString("<html><body><h1>Hello World!</h1></body></html>");
// at this point the "pdf" variable contains PDF raw data and
// can be sent in an HTTP response, saved to a file, etc.

// create an output stream for the conversion result
FileStream outputStream = new FileStream("HelloWorld.pdf", FileMode.CreateNew);

// run the conversion and write the result into the output stream
client.convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", outputStream);

// close the output stream
outputStream.Close();
' create the API client instance
Dim client As New pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d")

' run the conversion and write the result to a file
client.convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf")

' run the conversion and store the result into the "pdf" variable
Dim pdf() As Byte = client.convertString("<html><body><h1>Hello World!</h1></body></html>")
' at this point the "pdf" variable contains PDF raw data and
' can be sent in an HTTP response, saved to a file, etc.

' create an output stream for the conversion result
Dim outputStream As New FileStream("HelloWorld.pdf", FileMode.CreateNew)

' run the conversion and write the result into the output stream
client.convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", outputStream)

' close the output stream
outputStream.Close()
VB   C#

將 ASPX 頁面轉換為 PDF

以下的程式碼針對 IronPDF 和 PDFCrowd,從一個 ASP.NET 網頁建立一個 PDF 文件。

6.1. 使用 IronPDF 將 ASPX 頁面轉換為 PDF

以下代碼使用 IronPDF 將 ASPX 網頁文件渲染為 PDF。這是一行簡單易用的代碼。在渲染時可以添加更多的 PDF 設置選項。

protected void Page_Load(object sender, EventArgs e)
{
    IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
protected void Page_Load(object sender, EventArgs e)
{
    IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
	IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub
VB   C#

6.2. 使用 PDFCrowd 將 ASPX 頁面轉換為 PDF

以下代碼使用 PDFCrowd 將 ASPX 網頁文件渲染為 PDF。這使您能夠設置完整的 HTTP 響應標頭,並在 HTTP 響應中發送結果,以便在網頁瀏覽器中以 PDF 格式查看。

// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and store the result into the "pdf" variable
byte [] pdf = client.convertUrl("https://en.wikipedia.org");

// set HTTP response headers
Response.ContentType = "application/pdf";
Response.Headers.Add("Cache-Control", "max-age=0");
Response.Headers.Add("Accept-Ranges", "none");
Response.Headers.Add("Content-Disposition", "attachment; filename*=UTF-8''" + Uri.EscapeUriString("result.pdf"));

// send the result in the HTTP response
Response.OutputStream.Write(pdf, 0, pdf.Length);
Response.Flush();
// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");

// run the conversion and store the result into the "pdf" variable
byte [] pdf = client.convertUrl("https://en.wikipedia.org");

// set HTTP response headers
Response.ContentType = "application/pdf";
Response.Headers.Add("Cache-Control", "max-age=0");
Response.Headers.Add("Accept-Ranges", "none");
Response.Headers.Add("Content-Disposition", "attachment; filename*=UTF-8''" + Uri.EscapeUriString("result.pdf"));

// send the result in the HTTP response
Response.OutputStream.Write(pdf, 0, pdf.Length);
Response.Flush();
' create the API client instance
Dim client As New pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d")

' run the conversion and store the result into the "pdf" variable
Dim pdf() As Byte = client.convertUrl("https://en.wikipedia.org")

' set HTTP response headers
Response.ContentType = "application/pdf"
Response.Headers.Add("Cache-Control", "max-age=0")
Response.Headers.Add("Accept-Ranges", "none")
Response.Headers.Add("Content-Disposition", "attachment; filename*=UTF-8''" & Uri.EscapeUriString("result.pdf"))

' send the result in the HTTP response
Response.OutputStream.Write(pdf, 0, pdf.Length)
Response.Flush()
VB   C#

7. 將 XML 轉換為 PDF

以下程式碼使用 IronPDF 和 PDFCrowd API 將 XML 轉換為 PDF。

7.1. 使用 IronPDF 將 XML 轉換為 PDF

直接用 C# 將 XML 轉換為 PDF 可能是一個複雜的挑戰。我們發現在 C# 中將 XML 轉換為 PDF 時,最好從 XSLT 開始。XML 可以通過 HTML 呈現為 PDF。(5) 使用 XLST 轉換。

private void XMLtoPDF(string XSLT, string XML)
{
    XslCompiledTransform transform = new XslCompiledTransform();
    using(XmlReader reader = XmlReader.Create(new StringReader(XSLT)))  
    {
        transform.Load(reader);
    }
    StringWriter results = new StringWriter();
    using(XmlReader reader = XmlReader.Create(new StringReader(XML))) 
    {
        transform.Transform(reader, null, results);
    }
    IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
    // options, headers, and footers may be set there
    // Render our XML as a PDF via XSLT
    using var PDF = Renderer.RenderHtmlAsPdf(results.ToString())l
    PDF.SaveAs("XMLtoPDF.pdf");
}
private void XMLtoPDF(string XSLT, string XML)
{
    XslCompiledTransform transform = new XslCompiledTransform();
    using(XmlReader reader = XmlReader.Create(new StringReader(XSLT)))  
    {
        transform.Load(reader);
    }
    StringWriter results = new StringWriter();
    using(XmlReader reader = XmlReader.Create(new StringReader(XML))) 
    {
        transform.Transform(reader, null, results);
    }
    IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
    // options, headers, and footers may be set there
    // Render our XML as a PDF via XSLT
    using var PDF = Renderer.RenderHtmlAsPdf(results.ToString())l
    PDF.SaveAs("XMLtoPDF.pdf");
}
Private Sub XMLtoPDF(ByVal XSLT As String, ByVal XML As String)
	Dim transform As New XslCompiledTransform()
	Using reader As XmlReader = XmlReader.Create(New StringReader(XSLT))
		transform.Load(reader)
	End Using
	Dim results As New StringWriter()
	Using reader As XmlReader = XmlReader.Create(New StringReader(XML))
		transform.Transform(reader, Nothing, results)
	End Using
	Dim Renderer As New IronPdf.ChromePdfRenderer()
	' options, headers, and footers may be set there
	' Render our XML as a PDF via XSLT
	Dim PDF = Renderer.RenderHtmlAsPdf(results.ToString())l PDF.SaveAs("XMLtoPDF.pdf")
End Sub
VB   C#

XSLT 文件的結構如下:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <p>Titles:
    <xsl:for-each select="catalog/cd">
      <xsl:value-of select="title"/>
      <xsl:if test="position() < last()-1">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()-1">
        <xsl:text>, and </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()">
        <xsl:text>!</xsl:text>
      </xsl:if>
    </xsl:for-each>
    </p>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <p>Titles:
    <xsl:for-each select="catalog/cd">
      <xsl:value-of select="title"/>
      <xsl:if test="position() < last()-1">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()-1">
        <xsl:text>, and </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()">
        <xsl:text>!</xsl:text>
      </xsl:if>
    </xsl:for-each>
    </p>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2> My CD Collection</h2> <p> Titles: <xsl:for-@each @select="catalog/cd"> <xsl:value-@of @select="title"/> <xsl:if test="position() < last()-1"> <xsl:text>, </xsl:text> </xsl:if> <xsl:if test="position()=last()-1"> <xsl:text>, @and </xsl:text> </xsl:if> <xsl:if test="position()=last()"> <xsl:text>!</xsl:text> </xsl:if> </xsl:for-@each> </p> </body> </html> </xsl:template> </xsl:stylesheet>
VB   C#

7.2. 使用 PDFCrowd 將 XML 轉換為 PDF

PDFCrowd API 客戶端支持渲染 HTML 模板。模板語法基於 Jinja 模板渲染引擎。PDFCrowd API 客戶端還支持 XML 格式,並且可以與此語法一起使用。

// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}");

// configure the conversion
client.setDataString(@"<?xml version=""1.0"" encoding=""UTF-8""?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>");

// run the conversion and write the result to a file
client.convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf");
// create the API client instance
pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}");

// configure the conversion
client.setDataString(@"<?xml version=""1.0"" encoding=""UTF-8""?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>");

// run the conversion and write the result to a file
client.convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf");
' create the API client instance
Dim client As New pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}")

' configure the conversion
client.setDataString("<?xml version=""1.0"" encoding=""UTF-8""?>
        <data>
          <name>World</name>
          <product>Pdfcrowd API</product>
        </data>")

' run the conversion and write the result to a file
client.convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf")
VB   C#

8. 將圖片轉換為PDF

8.1. 使用 IronPDF 將圖像轉換為 PDF

在 IronPDF 庫中,可以使用 IronPdf.ImageToPdfConverter 類輕鬆地從一個或多個圖像文件構建 PDF 文檔。

// One or more images as IEnumerable.  This example selects all JPEG images in a specific folder.
var ImageFiles = System.IO.Directory.EnumerateFiles(@"C:\project\assets").Where(f => f.EndsWith(".jpg") 
 f.EndsWith(".jpeg"));

// Convert the images to a PDF and save it.
using var PDF = ImageToPdfConverter.ImageToPdf(ImageFiles);
PDF.SaveAs(@"C:\project\composite.pdf");

//Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
// One or more images as IEnumerable.  This example selects all JPEG images in a specific folder.
var ImageFiles = System.IO.Directory.EnumerateFiles(@"C:\project\assets").Where(f => f.EndsWith(".jpg") 
 f.EndsWith(".jpeg"));

// Convert the images to a PDF and save it.
using var PDF = ImageToPdfConverter.ImageToPdf(ImageFiles);
PDF.SaveAs(@"C:\project\composite.pdf");

//Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

8.2. 使用 PDFCrowd 將圖片轉換為 PDF

PDFCrowd 也提供將圖片轉換為 PDF 的功能,並且有各種選項。它還提供從 URL 轉換圖片的選項。以下代碼顯示瞭如何從本地存儲中將圖片轉換為 PDF。

// create the API client instance
pdfcrowd.ImageToPdfClient client = new pdfcrowd.ImageToPdfClient("your_username", "your_apikey");

// run the conversion and write the result to a file
client.convertFileToFile("/path/to/logo.png", "logo.pdf");
// create the API client instance
pdfcrowd.ImageToPdfClient client = new pdfcrowd.ImageToPdfClient("your_username", "your_apikey");

// run the conversion and write the result to a file
client.convertFileToFile("/path/to/logo.png", "logo.pdf");
' create the API client instance
Dim client As New pdfcrowd.ImageToPdfClient("your_username", "your_apikey")

' run the conversion and write the result to a file
client.convertFileToFile("/path/to/logo.png", "logo.pdf")
VB   C#

9. 授權

PDFCrowd 是一個將其他格式在線轉換為 PDF 文件的網絡服務。它有不同的價格結構,最低為每月 11 美元,限額為 200 個信用點,其中 1 個信用點相當於 0.5Mb 的輸出數據。你也可以註冊免費試用。詳細的價格可以在這裡查看 PDFCrowd 定價頁面IronPDF,另一方面,是一個 C# PDF 庫。它對於開發是免費的,並且可以隨時獲取商業部署的授權。 授權可用 適用於單個專案使用、單一開發人員、代理機構和全球企業,以及SaaS和OEM再分配。所有許可證均包括:30天退款保證、一年的產品支持和更新、開發/測試/生產的有效性,以及永久許可證。 (一次性購買)Lite 套件起始價格為 $749。IronPDF 套件是永久的,沒有持續費用,而 PDFCrowd 則有持續費用。

10. 總結和結論

摘要

IronPDF 不會從遠端伺服器呈現 HTML 為 PDF。實際上,它在幕後啟動了一個符合標準的真實網頁瀏覽器實例。 (無需安裝任何額外的軟體)HTML 可以精確地呈現,並以矢量格式適合商業印刷的最高標準。輸出是一個乾淨且高質量的 PDF。它是公開商業的,所有許可證和價格詳情都在網站上公布。

PDFCrowd 也能將任何給定格式的 HTML 轉換為 PDF,具有最高的準確性且絕對不會有停機時間,因為它運行在多個位置的雲服務器上。PDFCrowd 是一個基於網頁的 API,提供將 HTML 轉換為 PDF 的在線服務。服務器端 API 客戶端庫讓你可以輕鬆使用 Pdfcrowd HTML to PDF API。這些庫可以在多種流行的服務器端編程語言中使用。價格詳情在網站上列出。

結論

IronPDF 相較於 PDFCrowd 有輕微的優勢,因為其安裝後即可離線工作。IronPDF 強烈推薦給實用的程式設計師,幫助他們有效且高效地工作。最重要的是,它節省時間。PDFCrowd 在處理不同伺服器端語言的 PDFs 時可以很有用。此外,IronPDF 套件提供終身授權,且無持續費用,而 PDFCrowd 則有持續費用。

< 上一頁
Accusoft Prizmdoc PDF Viewer 教程和比較
下一個 >
IronPDF和Docraptor - 全面比較

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

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