在生产环境中测试,无水印。
随时随地满足您的需求。
获得30天的全功能产品。
几分钟内就能启动并运行。
在您的产品试用期间,全面访问我们的支持工程团队。
在 .NET 环境中处理 PDF 文件时,开发人员需要一个可靠且功能丰富的库来处理常见任务,如文档创建、编辑、加密和HTML 转 PDF 转换。 IronPDF 和 PDFsharp 是两个受欢迎的库,但它们满足不同的需求。
IronPDF 是一个功能全面、高性能的 PDF 库,擅长将 HTML 转换为 PDF、PDF 安全性和高级 PDF 操作。 另一方面,PDFsharp 是一个轻量级的开源库,专注于 PDF 创建和基本编辑。 在它们之间进行选择取决于您项目的复杂性和要求。
在本指南中,我们将从关键功能、可用性、安全性、定价和支持等方面比较IronPDF和PDFsharp,帮助您确定适合.NET应用程序的最佳工具。
IronPDF 是一个功能丰富的 .NET 库,在许多领域表现出色,包括 HTML 到 PDF 转换、PDF 编辑和安全文档处理。 它可以通过 NuGet 包管理器控制台轻松添加到您的项目中,轻松集成到您的 C# 项目中。
其突出功能包括:
PDFsharp 是一个免费、开源的库,主要用于基本的 PDF 创建和操作。 虽然它没有IronPDF所提供的丰富功能集,但对于不需要复杂功能的简单项目来说,它是一个很好的选择。 PDFsharp的一些核心功能包括:
基本加密:为PDF文档添加基本密码保护。
🚨 关键限制:PDFsharp 本身不支持将 HTML 转换为 PDF,需要像 Polybioz.HtmlRenderer.PdfSharp.Core 这样的第三方工具,增加了复杂性。
IronPDF旨在跨平台使用,完全兼容.NET Core、.NET Framework和Azure,并支持Windows、macOS和Linux。 这使其成为需要在多个操作系统上运行的项目的理想选择,并确保该库与大多数开发环境具有通用兼容性。 该库能够与现代Web开发环境无缝集成,非常适合用于Web应用程序、云解决方案和企业系统。
PDFsharp主要为.NET Framework设计,并对.NET Core提供有限支持。 虽然有 .NET Core 版本,但它仍在开发中,某些功能对非 Windows 平台尚未完全优化。 Linux 和 macOS 用户可能会遇到兼容性问题,这使得 PDFsharp 成为跨平台应用程序的不太理想的选择。
IronPDF 提供了一个对开发人员友好的 API,抽象了处理 PDF 文件的复杂性。 无论您是生成 PDF 还是编辑现有文件,语法都简洁直观,开发人员只需几行代码即可实现复杂功能。
PDFsharp,尽管在文本生成和PDF处理等基本任务中相对容易使用,但在处理复杂文档生成和编辑时通常需要更多的手动操作。
IronPDF:将HTML转换为PDF
只需调用一个方法即可轻松将HTML片段和内容转换为PDF:
using IronPdf;
var renderer = new ChromePdfRenderer();
var content = "<h1>IronPDF Rocks!</h1>";
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("output.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
var content = "<h1>IronPDF Rocks!</h1>";
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("output.pdf");
Imports IronPdf
Private renderer = New ChromePdfRenderer()
Private content = "<h1>IronPDF Rocks!</h1>"
Private pdf = renderer.RenderHtmlAsPdf(content)
pdf.SaveAs("output.pdf")
✔ 简洁、清晰的代码
✔ 轻松从现有 HTML 内容进行转换
PDFsharp: 创建带有文本的PDF
PDFsharp 需要通过使用图形对象手动实现文本和内容的绘制:
using PdfSharp.Pdf;
using PdfSharp.Drawing;
var document = new PdfDocument();
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 20, XFontStyleEx.Bold);
gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black, new XPoint(50, 100));
document.Save("output.pdf");
using PdfSharp.Pdf;
using PdfSharp.Drawing;
var document = new PdfDocument();
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 20, XFontStyleEx.Bold);
gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black, new XPoint(50, 100));
document.Save("output.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Private document = New PdfDocument()
Private page = document.AddPage()
Private gfx = XGraphics.FromPdfPage(page)
Private font = New XFont("Arial", 20, XFontStyleEx.Bold)
gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black, New XPoint(50, 100))
document.Save("output.pdf")
🚨 限制:
❌ 手动实现 – 您必须手动定位元素。
❌ 更复杂的用于生成报告、发票或样式化内容。
IronPDF 擅长将 HTML 报告、网页和动态内容转换为 PDF,同时保留 CSS、JavaScript 和嵌入的图像。 因此,它非常适合:
将网页捕获为 PDF 以供离线使用。
IronPDF 代码示例 – 将 HTML 文件转换为 PDF 格式:
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("example.html");
pdf.SaveAs("example.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("example.html");
pdf.SaveAs("example.pdf");
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("example.html")
pdf.SaveAs("example.pdf")
输出
正如您所见,使用IronPDF,我们能够仅用三行简单的代码将一个带样式的HTML文件转换为PDF文档,并且没有损失任何原有的质量或布局! 如果您想了解IronPDF如何处理更多CSS密集型内容,为什么不看看我们将此URL的内容转换为PDF的示例?
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.JavaScript(5000);
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
pdf.SaveAs("Apple.pdf");
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.JavaScript(5000);
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
pdf.SaveAs("Apple.pdf");
Imports IronPdf
Private renderer As New ChromePdfRenderer()
renderer.RenderingOptions.EnableJavaScript = True
renderer.RenderingOptions.WaitFor.JavaScript(5000)
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.apple.com")
pdf.SaveAs("Apple.pdf")
输出
在这里,我们利用IronPDF的强大渲染选项,将网页内容转换为高质量的PDF,保持了所有原始CSS和JavaScript内容。
PDFsharp 没有原生支持 HTML 到 PDF 的转换。 如果您需要此功能,您必须使用像 Html Renderer 这样的第三方库,该库提供了使用静态渲染代码将 HTML 内容转换为 PDF 文档的能力。 由于这些限制,PDFsharp 通常最好用于:
以编程方式定义内容的发票、合同和报告。
使用 HtmlRenderer 的 PDFsharp 示例:
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
var document = new PdfSharpCore.Pdf.PdfDocument();
string htmlContent = File.ReadAllText("index.html");
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4);
document.Save("html-to-pdf-pdfsharp.pdf");
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
var document = new PdfSharpCore.Pdf.PdfDocument();
string htmlContent = File.ReadAllText("index.html");
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4);
document.Save("html-to-pdf-pdfsharp.pdf");
Imports PdfSharp.Pdf
Imports TheArtOfDev.HtmlRenderer.PdfSharp
Private document = New PdfSharpCore.Pdf.PdfDocument()
Private htmlContent As String = File.ReadAllText("index.html")
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4)
document.Save("html-to-pdf-pdfsharp.pdf")
输出
感谢HtmlRenderer插件,我们能够在保持大多数原始样式的情况下将大多数HTML内容转换为PDF,但在涉及更多CSS密集型内容时,它与IronPDF相比表现如何? 让我们看看将网页内容转换为PDF文件的过程:
using PdfSharpCore.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
public class Program
{
public static async Task Main(string[] args)
{
// Define the URL to fetch HTML content
string url = "https://www.example.com"; // Replace with the URL you want to convert
// Fetch HTML content from the URL
string htmlContent = await FetchHtmlFromUrl(url);
// Generate the PDF from the fetched HTML content
var document = new PdfSharpCore.Pdf.PdfDocument();
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4);
// Save the generated PDF to a file
document.Save("url-to-pdf-example.pdf");
System.Console.WriteLine("PDF created successfully!");
}
// Method to fetch HTML content from a URL
private static async Task<string> FetchHtmlFromUrl(string url)
{
using (HttpClient client = new HttpClient())
{
// Send GET request to fetch the HTML content of the URL
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
// Read the content as a string
string htmlContent = await response.Content.ReadAsStringAsync();
return htmlContent;
}
else
{
throw new Exception($"Failed to fetch content from URL. Status Code: {response.StatusCode}");
}
}
}
}
using PdfSharpCore.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
public class Program
{
public static async Task Main(string[] args)
{
// Define the URL to fetch HTML content
string url = "https://www.example.com"; // Replace with the URL you want to convert
// Fetch HTML content from the URL
string htmlContent = await FetchHtmlFromUrl(url);
// Generate the PDF from the fetched HTML content
var document = new PdfSharpCore.Pdf.PdfDocument();
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4);
// Save the generated PDF to a file
document.Save("url-to-pdf-example.pdf");
System.Console.WriteLine("PDF created successfully!");
}
// Method to fetch HTML content from a URL
private static async Task<string> FetchHtmlFromUrl(string url)
{
using (HttpClient client = new HttpClient())
{
// Send GET request to fetch the HTML content of the URL
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
// Read the content as a string
string htmlContent = await response.Content.ReadAsStringAsync();
return htmlContent;
}
else
{
throw new Exception($"Failed to fetch content from URL. Status Code: {response.StatusCode}");
}
}
}
}
Imports PdfSharpCore.Pdf
Imports TheArtOfDev.HtmlRenderer.PdfSharp
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Public Class Program
Public Shared Async Function Main(ByVal args() As String) As Task
' Define the URL to fetch HTML content
Dim url As String = "https://www.example.com" ' Replace with the URL you want to convert
' Fetch HTML content from the URL
Dim htmlContent As String = Await FetchHtmlFromUrl(url)
' Generate the PDF from the fetched HTML content
Dim document = New PdfSharpCore.Pdf.PdfDocument()
PdfGenerator.AddPdfPages(document, htmlContent, PdfSharpCore.PageSize.A4)
' Save the generated PDF to a file
document.Save("url-to-pdf-example.pdf")
System.Console.WriteLine("PDF created successfully!")
End Function
' Method to fetch HTML content from a URL
Private Shared Async Function FetchHtmlFromUrl(ByVal url As String) As Task(Of String)
Using client As New HttpClient()
' Send GET request to fetch the HTML content of the URL
Dim response As HttpResponseMessage = Await client.GetAsync(url)
If response.IsSuccessStatusCode Then
' Read the content as a string
Dim htmlContent As String = Await response.Content.ReadAsStringAsync()
Return htmlContent
Else
Throw New Exception($"Failed to fetch content from URL. Status Code: {response.StatusCode}")
End If
End Using
End Function
End Class
输出
虽然PDFsharp无法处理与IronPDF相同的高强度CSS和JavaScript内容,但对于那些寻找轻量级PDF库用于不依赖于CSS或JavaScript内容的PDF生成任务的人来说,它仍然是一个强有力的竞争者。 虽然需要额外的库来进行HTML转换,但PDFsharp能够在.NET生态系统中从头创建PDF文件。
IronPDF 是开发人员处理安全 PDF 的首选,尤其适用于需要遵循严格数据保护法规的应用程序。 它提供先进的安全功能,旨在确保您的PDF文档保持安全并防篡改,使其适用于金融、医疗和法律等行业。
IronPDF 的使用案例:
GDPR 和 HIPAA 合规性:在处理个人或敏感信息时,IronPDF 支持符合 GDPR 和 HIPAA 等法规的加密标准,为处理安全客户数据的开发人员提供安心。
IronPDF 的加密功能包括用户级和拥有者级密码,这意味着您可以限制访问 PDF 或限制特定操作,例如打印、复制或编辑。 此外,它允许您将数字签名应用到PDF,确保数据的完整性和不可否认性,使其非常适合法律文件。 这些功能在文件安全至关重要的工作流程中尤其有用。
IronPDF 代码示例 – 使用密码加密 PDF:
using IronPdf;
var pdf = PdfDocument.FromFile("ConfidentialDocument.pdf");
pdf.SecuritySettings.UserPassword = "user";
pdf.SecuritySettings.OwnerPassword = "owner";
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SaveAs("ConfidentialDocumentSecured.pdf");
using IronPdf;
var pdf = PdfDocument.FromFile("ConfidentialDocument.pdf");
pdf.SecuritySettings.UserPassword = "user";
pdf.SecuritySettings.OwnerPassword = "owner";
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SaveAs("ConfidentialDocumentSecured.pdf");
Imports IronPdf
Private pdf = PdfDocument.FromFile("ConfidentialDocument.pdf")
pdf.SecuritySettings.UserPassword = "user"
pdf.SecuritySettings.OwnerPassword = "owner"
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SaveAs("ConfidentialDocumentSecured.pdf")
输出
在此示例中,IronPDF加密PDF并限制用户操作,确保文档受到保护,防止未经授权的访问或篡改。
虽然PDFsharp提供基本的密码保护,但它缺乏诸如数字签名、水印或复杂加密等高级功能。 对于只需限制PDF访问或应用基本密码的简单用例,PDFsharp 是一个不错的选择。 然而,如果您的应用程序需要更高级的安全功能,例如安全的文档签名或加密以满足合规标准,您可能会发现PDFsharp有所不足。
PDFsharp的使用案例:
机密文件的基本加密:如果您的应用程序不需要合规驱动的安全性,但您仍希望确保未经授权的用户无法打开敏感的PDF文件,PDFsharp的密码保护是一个简单的解决方案。
然而,PDFsharp 的加密能力相较于 IronPDF 有限,因此在需要强大安全性的情况下并不适用。 它可以通过用户密码保护PDF并限制某些操作,比如打印和复制,但它不提供金融或医疗等行业所需的强大加密标准。
PDFsharp 代码示例——基础 PDF 加密:
using PdfSharp.Pdf;
using PdfSharp.Pdf.Security;
using PdfSharp.Drawing;
// Create new document
var document = new PdfSharp.Pdf.PdfDocument();
// Add a page and draw something on it
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 16, XFontStyleEx.Bold);
gfx.DrawString("Confidential Document", font, XBrushes.Black, new XPoint(50, 50));
// Set password protection
document.SecuritySettings.UserPassword = "password123";
document.SecuritySettings.OwnerPassword = "admin456";
// Save the encrypted PDF
document.Save("pdfsharp-encrypted.pdf");
using PdfSharp.Pdf;
using PdfSharp.Pdf.Security;
using PdfSharp.Drawing;
// Create new document
var document = new PdfSharp.Pdf.PdfDocument();
// Add a page and draw something on it
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 16, XFontStyleEx.Bold);
gfx.DrawString("Confidential Document", font, XBrushes.Black, new XPoint(50, 50));
// Set password protection
document.SecuritySettings.UserPassword = "password123";
document.SecuritySettings.OwnerPassword = "admin456";
// Save the encrypted PDF
document.Save("pdfsharp-encrypted.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.Security
Imports PdfSharp.Drawing
' Create new document
Private document = New PdfSharp.Pdf.PdfDocument()
' Add a page and draw something on it
Private page = document.AddPage()
Private gfx = XGraphics.FromPdfPage(page)
Private font = New XFont("Arial", 16, XFontStyleEx.Bold)
gfx.DrawString("Confidential Document", font, XBrushes.Black, New XPoint(50, 50))
' Set password protection
document.SecuritySettings.UserPassword = "password123"
document.SecuritySettings.OwnerPassword = "admin456"
' Save the encrypted PDF
document.Save("pdfsharp-encrypted.pdf")
输出
在此代码中,PDFsharp 只是对 PDF 文档应用用户密码以限制访问。
IronPDF 在需要全面编辑 PDF、消除敏感信息以及处理多种文件格式(如 DOCX 转换为 PDF)的场景中表现出色。 它非常适合从事需要高级PDF操作的应用程序开发的开发人员,能够轻松集成到企业工作流程中。
IronPDF 的实际应用案例:
可编辑的PDF表单:如果您正在构建交互式PDF表单,允许用户输入数据(例如,申请表、调查问卷、反馈表),IronPDF允许您创建和修改可填写的表单。 此功能通常用于人力资源、教育和客户支持等行业。
示例用例 – 将DOCX转换为PDF并添加水印: 在企业环境中,IronPDF可以用于将Word文档转换为PDF,然后为品牌或安全目的添加水印。 使用IronPDF,您可以将水印应用到指定页面或整个PDF文档的所有页面。
在这里,我们将选取一个示例 DOCX 文件,并应用水印将其标记为草稿,附上示例公司的品牌标识。
using IronPdf;
using IronPdf.Editing;
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
PdfDocument pdf = renderer.RenderDocxAsPdf("document.docx");
var watermark = "<h1 style='Color: red; font-size: 60px'>DRAFT</h1><img style='width: 200px' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>";
pdf.ApplyWatermark(watermark, opacity:75, VerticalAlignment.Top, HorizontalAlignment.Right);
pdf.SaveAs("output.pdf");
using IronPdf;
using IronPdf.Editing;
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
PdfDocument pdf = renderer.RenderDocxAsPdf("document.docx");
var watermark = "<h1 style='Color: red; font-size: 60px'>DRAFT</h1><img style='width: 200px' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>";
pdf.ApplyWatermark(watermark, opacity:75, VerticalAlignment.Top, HorizontalAlignment.Right);
pdf.SaveAs("output.pdf");
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New DocxToPdfRenderer()
Private pdf As PdfDocument = renderer.RenderDocxAsPdf("document.docx")
Private watermark = "<h1 style='Color: red; font-size: 60px'>DRAFT</h1><img style='width: 200px' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>"
pdf.ApplyWatermark(watermark, opacity:=75, VerticalAlignment.Top, HorizontalAlignment.Right)
pdf.SaveAs("output.pdf")
输出
在此示例中,IronPDF 首先将 DOCX 文档 转换为 PDF,然后添加 水印 以确保该文档被标记为 “DRAFT”。 此功能对于需要在确保文档安全的同时分发敏感信息或跟踪哪些文档为草稿的公司非常有用。
PDFsharp 更适合用于基本的 PDF 操作,适合需要轻量级编辑和从头创建文档的情况。 它擅长执行从头创建简单PDF、修改现有PDF以及应用基本编辑等任务。 然而,当涉及到更复杂的操作时,例如高级编辑、文档转换或处理表单数据,PDFsharp 的功能与 IronPDF 相比要有限得多。
PDFsharp的实际用例:
基本修订:虽然PDFsharp不提供像IronPDF那样的高级修订功能,但它可以用于基本修订,例如使用形状或纯色覆盖文本或图像。 这对于低安全性的文档或不需要遵从严格数据隐私法的应用程序来说可能已经足够。
示例用例:在商业环境中,PDFsharp 可用于从数据库中提取数据生成报告、合并多个文件为一个文件,或对文档的某部分进行编辑以供内部使用。
PDFsharp 代码示例 – 合并两个 PDF:
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
// Open the first PDF
PdfDocument document1 = PdfReader.Open("document1.pdf", PdfDocumentOpenMode.Import);
// Open the second PDF
PdfDocument document2 = PdfReader.Open("document2.pdf", PdfDocumentOpenMode.Import);
// Create a new PDF document for the merged file
PdfDocument outputDocument = new PdfDocument();
// Add pages from the first document
foreach (PdfPage page in document1.Pages)
{
outputDocument.AddPage(page);
}
// Add pages from the second document
foreach (PdfPage page in document2.Pages)
{
outputDocument.AddPage(page);
}
// Save the merged PDF
outputDocument.Save("merged-document.pdf");
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
// Open the first PDF
PdfDocument document1 = PdfReader.Open("document1.pdf", PdfDocumentOpenMode.Import);
// Open the second PDF
PdfDocument document2 = PdfReader.Open("document2.pdf", PdfDocumentOpenMode.Import);
// Create a new PDF document for the merged file
PdfDocument outputDocument = new PdfDocument();
// Add pages from the first document
foreach (PdfPage page in document1.Pages)
{
outputDocument.AddPage(page);
}
// Add pages from the second document
foreach (PdfPage page in document2.Pages)
{
outputDocument.AddPage(page);
}
// Save the merged PDF
outputDocument.Save("merged-document.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
' Open the first PDF
Private document1 As PdfDocument = PdfReader.Open("document1.pdf", PdfDocumentOpenMode.Import)
' Open the second PDF
Private document2 As PdfDocument = PdfReader.Open("document2.pdf", PdfDocumentOpenMode.Import)
' Create a new PDF document for the merged file
Private outputDocument As New PdfDocument()
' Add pages from the first document
For Each page As PdfPage In document1.Pages
outputDocument.AddPage(page)
Next page
' Add pages from the second document
For Each page As PdfPage In document2.Pages
outputDocument.AddPage(page)
Next page
' Save the merged PDF
outputDocument.Save("merged-document.pdf")
输出
此代码演示了如何使用PDFsharp**合并两个PDF文档**为一个。 这是需要将多个报告、发票或其他文件合并为单个PDF的应用程序的常见用例。
IronPDF 和 PDFsharp 在定价和许可方面提供不同的方法,以满足各种需求。 IronPDF 提供永久授权模式,而 PDFsharp 是开源和免费使用的。
IronPDF使用永久授权模式,这意味着用户可以享有终身访问权限,并提供年度更新。 它提供基于使用情况的分级定价,包括个人、团队或企业许可证。 用户可以访问免费试用,在购买前测试该工具。 商业许可证用户还将获得技术支持和功能更新。
PDFsharp 在MIT 许可证下免费发布,这意味着它是开源的,可用于个人和商业用途。 然而,它不提供高级支持,用户只能依靠社区论坛寻求帮助。 这适合较小或开源项目,但可能需要外部帮助以满足更复杂的需求。
IronPDF 在开发者支持方面表现出色,提供详细的文档和多种帮助渠道。 与PDFsharp不同,IronPDF提供了有结构的资源,可帮助开发人员在整个集成过程中。
IronPDF提供全面的文档,包括分步指南、API参考和代码示例。 有专门的支持团队可用于解答技术问题。 此外,在线知识库提供故障排除解决方案和有用的提示。 对于企业客户,优先支持可确保更快地解决问题。
IronPDF 还促进了一个活跃的开发者社区。 用户可以参与社区论坛,在那里他们可以提问、分享经验和寻找解决方案。 此外,教程和视频指南帮助用户快速入门。 IronPDF 也在 GitHub 上存在,允许社区报告错误和建议功能。
PDFsharp 的支持主要来自其 GitHub 存储库和社区论坛,如 Stack Overflow。 开发人员可以报告问题、浏览解决方案,或提出问题。 然而,文档有限,详细指南或官方教程稀缺,开发人员需要依靠社区贡献或反复试错。
缺乏官方支持意味着开发者可以通过GitHub为PDFsharp做出贡献,改进文档或添加功能。 尽管有用户贡献的教程,但缺少专门的支持团队意味着故障排除可能需要更长时间。
在选择 IronPDF 和 PDFsharp 之间时,决策主要取决于您项目的要求。 IronPDF 是一款功能强大且丰富的解决方案,具有高级功能,如将 HTML 转换为 PDF、强大的加密以及强大的跨平台支持。 它非常适合需要高质量PDF操作、安全功能和专用支持的企业、公司和开发人员。
另一方面,PDFsharp 是一个可靠的开源选择,适用于不需要高级功能的简单项目,提供了易用性和灵活性,能够进行基本的 PDF 创建和编辑。
如果您正在寻找具有广泛功能的多合一 PDF 解决方案,我们鼓励您探索 IronPDF。 凭借其商业支持和持续更新,IronPDF 致力于根据您的开发需求进行扩展,并确保高效、安全地处理您的 PDF。 立即尝试 IronPDF,探索它如何简化您的 PDF 工作流程!