在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
PDF 文档已成为数字生态系统的重要组成部分,是共享和展示信息的通用格式。在软件开发领域,一直需要能有效创建、修改和转换 PDF 文件的工具。这就是 NuGet PDF 生成器的用武之地,它为开发人员提供了一种生成 PDF 文档并将 PDF 功能集成到其应用程序中的便捷方法。
IronPDF 就是这样一个功能强大的 .NET PDF 库,它可以作为一个 NuGet 包提供。在本文中,我们将深入了解 NuGet 的世界,探索 IronPDF 库的功能,并学习如何轻松创建和生成 PDF 文件。
NuGet 是 Microsoft 开发平台(包括 .NET Framework 和 .NET Core)的软件包管理器。它通过自动化软件包安装、版本管理和依赖关系跟踪,简化了将第三方库和工具集成到项目中的过程。
NuGet 拥有超过 100,000 个软件包的庞大资源库,开发人员可以毫不费力地添加、更新和删除功能,而无需手动管理 DLL 或担心兼容性问题。我们可以用它在 visual studio 中安装 NuGet 软件包。
IronPDF 是一款功能强大、用途广泛的 .NET 库,可帮助开发人员在其应用程序中创建、修改和转换 PDF 文档。可作为 软件包IronPDF 简化了 PDF 操作,使其成为开发人员处理 .NET Framework 和 .NET Core 项目的宝贵工具。
IronPDF 的主要功能包括从零开始创建新的 PDF 文档、将 HTML 内容转换为 PDF 文件、修改现有 PDF 文件以及提供高质量的渲染和排版。该库简化了从现有 HTML 页面生成 PDF 的过程。它可以使用 HTML 字符串、HTML 文件或 URL 创建 PDF 文件。
IronPDF 能够将 将 HTML 内容转换为 PDF 文件。这样,开发人员就能从现有的 HTML 页面创建 PDF 文件,或从用户生成的内容动态生成 PDF 文件。下面是一个如何将 HTML 文件转换为 PDF 文档的示例:
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("Hello World");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("Hello World");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
Imports IronPdf
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Create a PDF from a HTML string using C#
Private pdf = renderer.RenderHtmlAsPdf("Hello World")
' Export to a file or Stream
pdf.SaveAs("output.pdf")
IronPDF 允许开发人员 将网页直接转换为 PDF 文档.在开发人员需要从实时网页生成 PDF 文档或保存在线内容以供离线查看、存档或共享时,该功能尤其有用。
利用 IronPDF 的 HTML 到 PDF 转换功能,开发人员只需几行代码就能轻松地将整个网页(包括文本、图像和样式)转换为 PDF 文档。以下是该功能工作原理的简要介绍:
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
Imports IronPdf
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Create a PDF from a URL or local file path
Private pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Export to a file or Stream
pdf.SaveAs("url.pdf")
IronPDF 还能让开发人员修改现有的 PDF 文档和文件,从而轻松添加或删除内容、合并文档以及应用安全设置。下面是一个例子 如何在 PDF 文档中添加水印:
using IronPdf;
// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
using IronPdf;
// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf
' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")
本示例项目演示了如何从 URL 创建 PDF 文档,为每页添加水印,并将修改后的文档保存为新文件。
除了前面讨论的基本 PDF 文件创建操作外,IronPDF 还提供了高级功能,可进一步增强您的 PDF 文档生成和管理能力。其中一些功能包括
合并 PDF 文档: IronPDF 使您能够 将多个 PDF 文件合并为单一文件这样就可以轻松编译和组织相关内容。
using IronPdf;
var html_a = @" [PDF_A]
[PDF_A] 1st Page
[PDF_A] 2nd Page";
var html_b = @" [PDF_B]
[PDF_B] 1st Page
[PDF_B] 2nd Page";
var renderer = new ChromePdfRenderer();
var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.pdf");
using IronPdf;
var html_a = @" [PDF_A]
[PDF_A] 1st Page
[PDF_A] 2nd Page";
var html_b = @" [PDF_B]
[PDF_B] 1st Page
[PDF_B] 2nd Page";
var renderer = new ChromePdfRenderer();
var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.pdf");
Imports IronPdf
Private html_a = " [PDF_A]
[PDF_A] 1st Page
[PDF_A] 2nd Page"
Private html_b = " [PDF_B]
[PDF_B] 1st Page
[PDF_B] 2nd Page"
Private renderer = New ChromePdfRenderer()
Private pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
Private pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
Private merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
merged.SaveAs("Merged.pdf")
PDF 表单: IronPDF 支持创建和管理 PDF 表单。 操作 PDF 表格允许开发人员生成带有可填写字段的动态交互式 PDF 文档。
using IronPdf;
using System;
// Step 1. Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
Editable PDF Form
First name:
Last name:
Please specify your gender:
Female
Male
Non-Binary / Other
Please select all medical conditions that apply:
Hypertension
Heart Disease
Stoke
Diabetes
Kidney Disease
";
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");
// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");
// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.GetFieldByName("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);
// Set and Read the value of the "lastname" field
IronPdf.Forms.FormField LastNameField = FormDocument.Form.GetFieldByName("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);
FormDocument.SaveAs("FilledForm.pdf");
using IronPdf;
using System;
// Step 1. Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
Editable PDF Form
First name:
Last name:
Please specify your gender:
Female
Male
Non-Binary / Other
Please select all medical conditions that apply:
Hypertension
Heart Disease
Stoke
Diabetes
Kidney Disease
";
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");
// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");
// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.GetFieldByName("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);
// Set and Read the value of the "lastname" field
IronPdf.Forms.FormField LastNameField = FormDocument.Form.GetFieldByName("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);
FormDocument.SaveAs("FilledForm.pdf");
Imports IronPdf
Imports System
' Step 1. Creating a PDF with editable forms from HTML using form and input tags
' Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
Private Const formHtml As String = "
Editable PDF Form
First name:
Last name:
Please specify your gender:
Female
Male
Non-Binary / Other
Please select all medical conditions that apply:
Hypertension
Heart Disease
Stoke
Diabetes
Kidney Disease
"
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf")
' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")
' Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.GetFieldByName("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)
' Set and Read the value of the "lastname" field
Dim LastNameField As IronPdf.Forms.FormField = FormDocument.Form.GetFieldByName("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)
FormDocument.SaveAs("FilledForm.pdf")
PDF 安全性: IronPDF 提供以下选项 保护您的 PDF 文档包括密码保护和加密。
using IronPdf;
// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf");
//Edit file security settings
//The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
//Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SaveAs("secured.pdf");
using IronPdf;
// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf");
//Edit file security settings
//The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
//Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SaveAs("secured.pdf");
Imports IronPdf
' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf")
'Edit file security settings
'The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
'Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret" ' password to edit the pdf
pdf.SaveAs("secured.pdf")
对于需要在其.NET应用程序中实现全面的PDF功能的开发人员来说,IronPDF的高级功能使其成为一个无价的工具。从合并文档、管理表单到保护内容和自定义渲染,IronPDF 为您的所有 PDF 需求提供了强大的解决方案。
NuGet 上提供的 IronPDF 库是一个功能强大、用途广泛的 .NET PDF 库,可简化在应用程序中创建、修改和转换 PDF 文件的过程。通过利用其广泛的功能(如生成新的 PDF 文档、将 HTML 转换为 PDF 以及修改现有的 PDF 文件),开发人员可以将 PDF 功能无缝集成到他们的 .NET Framework 和 .NET Core 项目中。有了 IronPDF,生成和管理 PDF 文档变得前所未有的简单。
IronPDF 提供 免费试用 的试用期,允许开发人员在决定购买前试用软件的特性和功能。如果开发人员在试用期后决定购买许可证,许可证的起始价格为 $749。价格可能因许可证类型和使用软件的开发人员数量而异。如果购买量较大,IronPDF 还可提供批量折扣。