产品比较

IronPDF与PDFCrowd的比较

发布 2021年十二月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,无需使用复杂的应用程序接口来定位或设计 PDF。 IronPDF 支持标准网络文档:HTML、ASPX、JS、CSS 和图像。

它还能让您使用 HTML5、CSS、JavaScript 和图像创建 .NET PDF 库。 你可以毫不费力地对 PDF 进行编辑、盖章以及添加页眉和页脚。 此外,它还可以非常容易地 阅读 PDF 文本和提取图像。

IronPDF C# 图书馆 - 突出特点

其中一些重要功能包括

创建 PDF 文件 (Html 转 PDF_)

  • 从HTML 4和5、CSS和JavaScript创建PDF文档
  • 从URL生成PDF文档
  • 使用自定义网络登录凭据、用户代理、代理、Cookie、HTTP头、表单变量加载URL,允许在HTML登录表单后登录。

    不需使用 Adobe Acrobat 编辑现有的 PDF 文档

  • 读取并填写表单字段数据
  • 从PDF中提取图像和文本
  • 在任何现有的PDF页面上打印新的HTML内容
  • 添加逻辑或HTML页眉和页脚

    修改现有 PDF 文档

  • 加载和解析现有的PDF文档
  • 合并和拆分 PDF 文档中的内容
  • 添加页眉、页脚、注释、书签、水印、文本和图像资源

    从多种格式转换

  • ASPX WebForms – 使用3行代码将ASP.NET WebForms转换为可在浏览器中查看的可下载PDF
  • HTML 文档 – 将 HTML 转换为 PDF
  • 自定义“基本URL”以允许整个网络上的可访问资产文件
  • 通过虚拟视口实现响应式布局 (宽度和高度)
  • 接受以任何主要文件编码方式编码的 HTML (默认为 UTF-8)

    保存并打印

  • 从文件、二进制数据或内存流中保存和加载数据
  • 屏幕或打印CSS媒体类型
  • 将 PDF 文件转化为 PrintDocument 对象,无需 Adobe 即可打印 (代码最少)
  • 导出包含API成功和源代码调试错误详情的官方日志文件。

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 网络应用程序 (.NET框架) 然后点击确定,如下图所示

    图 1 - 新建项目对话框

  • 在下一个屏幕中,选择 "Web 表单",如下图所示。

    图 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
  • 按回车键
  • 这将下载并安装软件包
  • 重新加载 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客户端库 for .NET

Pdfcrowd API客户端库允许您在HTML、PDF和各种图像格式之间进行转换。 .NET API 客户端库使得轻松实现 Pdfcrowd API 在您的 .NET 应用程序中。

有三种方式安装.NET的PDFCrowd API客户端库:

  1. 直接下载 Pdfcrowd 客户端的压缩包
  2. 通过 NuGet 包管理器安装 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
  • 按回车键
  • 这将下载并安装软件包
  • 重新加载 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 上
  • 在 Unix 上执行 make all #

    现在我们已经创建了项目并安装了必要的库,让我们开始比较IronPDF和PDFCrowd库在代码方面的不同。

4.从现有 URL 创建 PDF

这两个库都提供将 HTML 网页转换为 PDF 的功能。 让我们逐一看看每个库的代码。

4.1.使用 IronPDF 将现有 URL 转换为 PDF

IronPDF 可以将现有 URL 中的 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,将网址转换为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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
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();
IRON VB CONVERTER ERROR developers@ironsoftware.com
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();
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

7. 将 XML 转换为 PDF

以下代码将XML转换为IronPDF和PDFCrowd API的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 Client 支持渲染 HTML 模板。 模板语法基于 Jinja 模板渲染引擎。XML 格式也由 PDFCrowd API 客户端支持,并且可以使用此语法。

// 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
' One or more images as IEnumerable.  This example selects all JPEG images in a specific folder.
Dim ImageFiles = System.IO.Directory.EnumerateFiles("C:\project\assets").Where(Function(f) f.EndsWith(".jpg") f.EndsWith(".jpeg"))
' Convert the images to a PDF and save it.
Dim PDF = ImageToPdfConverter.ImageToPdf(ImageFiles)
PDF.SaveAs("C:\project\composite.pdf")
'Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
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天退款保证、一年的产品支持和更新、适用于开发/测试/生产的有效性,以及永久许可证。 (一次性购买). 精简版软件包从 $749 开始。 IronPDF套餐是永久性的,没有持续的费用,而相比之下,PDFCrowd则有持续的费用。

10.总结和结论

摘要

IronPDF 无法从远程服务器将 HTML 转换为 PDF。 它实际上在幕后启动了一个真实的、符合标准的网页浏览器实例。 (无需安装任何其他软件). HTML 以完全准确的方式呈现,并采用适合商业印刷最高标准的矢量格式。 输出的 PDF 文件干净整洁,质量上乘。 它是公开商业化的,许可和定价详情都公布在网站上。

PDFCrowd还能将任何给定格式的HTML准确无误地转换为PDF,并且因为在多个地点的云服务器上运行,所以完全没有停机时间。 PDFCrowd 是一个基于网络的 API,提供在线服务将内容转换为 PDF。 服务器端 API 客户端库使您能够轻松使用 Pdfcrowd HTML 转 PDF API。 这些库可用于多种流行的服务器端编程语言。 网站上列出了价格详情。

结论

IronPDF在安装后可以离线工作,相较于PDFCrowd有轻微的优势。 强烈推荐务实的编码人员使用 IronPDF,以提高工作效率和成效。 最重要的是,它可以节省时间。 PDFCrowd 在处理不同服务器端语言的 PDF 文件时可能非常有用。 此外,IronPDF 套餐提供终身许可证,没有持续的成本,而 PDFCrowd 则有持续的成本。

< 前一页
Accusoft Prizmdoc PDF 查看器教程和比较
下一步 >
IronPDF与Docraptor——全面比较

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

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