跳至页脚内容
使用IRONPDF

C#中的PDFium替代品使用IronPDF

PDFium库是由Google专门开发的开源渲染引擎,用于处理便携式文档格式(PDF)文件,无论是否含有图像,包括PNG等。然而,IronPDF不仅仅使用PDFium渲染接口引擎作为其源代码设置;它还在此基础上进行构建,以提供额外的功能,使得编写/测试项目源代码变得更加容易且没有错误或漏洞。 IronPDF 增加了将 HTML 文档转换为 PDF 文档的支持——这是 PDFium .NET SDK 并不支持的功能。

IronPDF 利用 PDFium 提供的开源技术的力量,为客户提供了一套全面的工具,开发能以某种方式处理 PDF 文件的交互式 Microsoft .NET Windows 应用程序。 这包括将 HTML 文件转换为 PDF 文件,拆分或合并 PDF 页面,从 PDF 文档中提取文本,向 PDF 文件添加签名或水印,填写 PDF 表单,打印 PDF 等。

class="hsg-featured-snippet">

如何在 C# 中使用 PDFium

  1. 安装 C# 的 IronPDF 库,以使用 PDFium 管理 PDF 文件
  2. 使用 RenderUrlAsPdf 方法生成与网站相同的 PDF
  3. 配置渲染选项以实现不同的页面设置和属性
  4. 将 PDF 导出为新文档
  5. 检查输出 PDF 以查看相同的格式

IronPDF 创建的 PDF 文件比 PDFium 更好

IronPDF在创建PDF方面对PDFium进行了显著的改进。 虽然 PDFium 可以创建和加载基本的 PDF,但缺少用户期望的许多现代 PDF 文档库特性。 IronPDF addresses this shortcoming with an easy-to-use API for creating complex PDFs with headers and footers, page count, page numbers, bookmarks, watermarks, and much more.

IronPDF 允许用户为 PDF 渲染自定义纸张大小。 这是示例代码的一瞥:

// Create a ChromePdfRenderer instance.
var renderer = new IronPdf.ChromePdfRenderer();

// Set the paper size to custom.
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Custom;

// Define custom height and width for the PDF.
int height = 5;
int width = 5;

// Assign the custom dimensions to the rendering options.
renderer.RenderingOptions.SetCustomPaperSizeInInches(height, width);
// Create a ChromePdfRenderer instance.
var renderer = new IronPdf.ChromePdfRenderer();

// Set the paper size to custom.
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Custom;

// Define custom height and width for the PDF.
int height = 5;
int width = 5;

// Assign the custom dimensions to the rendering options.
renderer.RenderingOptions.SetCustomPaperSizeInInches(height, width);
' Create a ChromePdfRenderer instance.
Dim renderer = New IronPdf.ChromePdfRenderer()

' Set the paper size to custom.
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Custom

' Define custom height and width for the PDF.
Dim height As Integer = 5
Dim width As Integer = 5

' Assign the custom dimensions to the rendering options.
renderer.RenderingOptions.SetCustomPaperSizeInInches(height, width)
$vbLabelText   $csharpLabel

IronPDF 快速生成高质量文档

在文档生成方面,速度和内存与质量同样重要。 使用 IronPDF,您不必在两者之间做出牺牲。 您可以从访问目录中的 HTML 文件快速生成高质量文档。

额外的环境配置

构建 PDFium 项目不是一项容易的任务。 这需要添加不同的模块和数据以嵌入 PDFium。 与 PDFium 不同,IronPDF 不需要任何额外的环境配置或外部依赖项。 相反,IronPDF 将所有必要的组件包含在其核心 API 中。 在安装 IronPDF 时,所有相关工具都会自动安装。

安全增强

IronPDF 还提供增强的库安全功能。 它支持加密和解密 PDF 文档。 它还提供多个选项来控制用户在打开文档后可以执行的操作,例如打印,复制和注释。

更好的支持和文档

IronPDF 提供了优于 PDFium 的出色支持和文档。 如果在使用 IronPDF 时遇到任何问题,我们的团队随时可以提供帮助。全面的文档以及图片,使得在您的 .NET 应用程序中开始使用 IronPDF 变得容易。

IronPDF 如何成为客户需求的最佳解决方案

IronPDF 是满足客户需求的最佳解决方案,因为:

  • 它与任何 .NET Web 应用程序轻松集成。
  • 它可以从 HTML 页面、CSS 和 JavaScript 文件创建 PDF 文件。
  • 对于需要从 PDF 文档提取数据或对现有文档和源代码进行更改的客户,IronPDF 库也非常有用。
  • IronPDF 提供出色的客户支持和全面的文档,帮助客户快速入门。
  • 还有一个免费试用版可以使用,所以客户可以在购买前试用该库。

了解有关在 .NET 应用程序中使用 IronPDF 的更多信息,请使用以下教程将 HTML 转换为 PDF

使用 IronPDF 有多么简单

请考虑以下演示,看看使用 IronPDF 是多么简单。 假设您有一个需要转换为 PDF 的 URL 路径; 使用 IronPDF 的转换过程很简单。 类库抽象了使用底层 IronPDF 库的所有细节。 Just add a reference to the IronPDF library or install it using the NuGet Package Manager and call the RenderUrlAsPdf method, passing in the URL path and the path where you want the PDF file to be saved using the SaveAs function. 您可以仅用两行代码轻松地将任何 URL 转换为 PDF 文档。

// Create a ChromePdfRenderer instance and store it in a variable.
var renderer = new ChromePdfRenderer();

// Render the URL as a PDF.
var page = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/");

// Save the rendered PDF to the specified file path.
page.SaveAs("website.pdf");
// Create a ChromePdfRenderer instance and store it in a variable.
var renderer = new ChromePdfRenderer();

// Render the URL as a PDF.
var page = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/");

// Save the rendered PDF to the specified file path.
page.SaveAs("website.pdf");
' Create a ChromePdfRenderer instance and store it in a variable.
Dim renderer = New ChromePdfRenderer()

' Render the URL as a PDF.
Dim page = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/")

' Save the rendered PDF to the specified file path.
page.SaveAs("website.pdf")
$vbLabelText   $csharpLabel

PDFium 在 C# 中的替代方案使用 IronPDF,图 1:IronPDF 输出 IronPDF 输出

结论

在 PDFium 项目基础上构建,为客户/开发者提供了一个可靠、最新且功能丰富的 PDF 库。 我们的客户可以确保他们的文档在任何设备或平台上看起来都很出色。 他们还可以利用 IronPDF 代码所提供的强大功能,使他们能够快速安全地创建、编写和共享 PDF。

IronPDF 提供免费试用期,因此您可以在购买前测试软件。 价格从仅$liteLicense开始,相比其他类似的 PDF 渲染软件,非常实惠。 如果您需要购买多个许可证,公司提供了显著的折扣。 通过购买Iron Suite,您可以用两个的价格购买五个产品许可证。

常见问题解答

什么是 PDFium 以及如何在 .NET 应用程序中使用?

PDFium 是由 Google 开发的开源渲染引擎,用于处理 PDF 文件。在 .NET 应用程序中,它作为类似 IronPDF 的库的基础,扩展其功能以提供增强的 PDF 管理能力。

如何在.NET应用程序中将HTML转换为PDF?

IronPDF 提供诸如 RenderHtmlAsPdf 的方法,将 HTML 字符串转换为 PDF 文档。它简化了在 .NET 应用程序中整合 HTML 至 PDF 转换的过程。

IronPDF 相对于 PDFium 提供哪些附加功能?

IronPDF 通过提供 HTML 至 PDF 转换、PDF 拆分和合并、文本提取、添加签名或水印等功能来扩展 PDFium,所有这些都无需额外配置。

IronPDF 可以用于加密 PDF 文件吗?

是的,IronPDF 支持加密和解密 PDF 文件,提供了控制用户权限选项,例如打印和复制。

IronPDF 如何简化创建复杂 PDF 文档的过程?

IronPDF 提供了一个用户友好的 API,允许开发者轻松创建具有自定义页眉、页脚、书签和页码等功能的复杂 PDF,从而提高 .NET 应用中的生产力。

在 .NET 应用中使用 IronPDF 是否需要额外的设置?

不需要,IronPDF 将所有必要的组件嵌入其核心 API 中,消除额外配置或外部依赖的需要,与标准 PDFium 不同。

IronPDF 是否支持自定义纸张尺寸?

是的,IronPDF 支持自定义纸张尺寸,允许开发者根据需要指定 PDF 文档的尺寸。

开发人员可以通过哪些选项在购买前测试 IronPDF?

IronPDF 提供免费试用期,允许开发人员在购买前测试其功能及与 .NET 应用程序的集成。

IronPDF 如何帮助将 URL 转换为 PDF 文档?

IronPDF 的 ChromePdfRenderer 类中的 RenderUrlAsPdf 方法允许开发者将 URL 中的网页直接转换为 PDF 文档,简化网络内容存档。

IronPDF 提供怎样的客户支持?

IronPDF 提供优质的客户支持,并附有全面的文档,以帮助开发者有效利用库的广泛功能。

IronPDF 是否完全兼容 .NET 10?面向 .NET 10 有哪些好处?

是的——IronPDF 完全兼容 .NET 10,支持最新的运行时和 C# 语言特性。面向 .NET 10 可带来诸多优势,例如性能提升(例如减少堆分配、数组接口方法去虚拟化)、更佳的内存利用率、平台级增强功能,以及对 Windows、macOS、Linux 和容器/云部署的支持。这确保了 PDF 的创建和处理速度更快、效率更高,并且面向未来。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。