在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
IronPDF和 EvoPdf 是用于创建、编辑和管理 PDF 文档的两个重要的 .NET 库。 每个产品都有独特的优势和功能,专为在 .NET 平台上工作的开发人员量身定制。 本文将深入比较这两个库,重点关注其功能、兼容性、许可、支持等方面。
希望在阅读完这篇文章后,您可以识别出哪些库最适合您的 PDF 需求,并能够进行比较分析,若您想要进一步研究更多的 PDF 库选项。
IronPDF是一个.NET PDF库,使开发人员能够以编程方式创建、编辑和操作PDF文档。 它以易于使用、广泛兼容.NET版本以及能够将HTML、ASPX和图像文件转换为PDF的功能而闻名,同时保持与原始内容的高度一致性。 IronPDF的详尽文档、强大的客户支持和丰富的功能集,使其成为开发人员在其.NET应用程序中集成PDF功能的首选。
EvoPdf 是另一个用于 HTML 到 PDF 转换及其他 PDF 操作任务的 .NET 库。 它为HTML标签、CSS、JavaScript以及其他现代网页技术提供高级支持,使得可以从网页内容生成高质量的PDF文档。 EvoPdf因其渲染能力和广泛支持Web标准而受到好评,使其成为专注于Web到PDF转换的开发人员的宝贵工具。
IronPDF 提供广泛的跨平台兼容性,使其成为适用于各种环境的多功能工具:
.NET 版本:
完全使用C#编写并支持C#,VB.NET,和 F#
.NET Core(8、7、6、5 和 3.1+)
操作系统和处理器: 支持多种不同的操作系统和处理器,包括Windows、Mac、Linux、x64、x86、ARM。
有关IronPDF兼容性的更多详细信息,请访问IronPDF 兼容性.
IronPDF 和 EvoPdf 都提供强大的 PDF 操作功能,但开发人员应考虑以下明显的差异:
集成:无缝集成到 ASP.NET和MVC应用程序。
要获取 IronPDF 功能的完整列表,请访问IronPDF 功能.
以下是IronPDF与EvoPdf之间主要功能的详细比较,并附有具体代码示例以展示其用法。
IronPDF:
using IronPdf;
// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from an HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
using IronPdf;
// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from an HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
Imports IronPdf
' Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = True
' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()
' Create a PDF from an HTML string using C#
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
' Export to a file or Stream
pdf.SaveAs("output.pdf")
EvoPdf:
using EvoPdf;
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert the HTML string to a PDF file
converter.ConvertHtmlToFile("<b>Hello World</b> from EVO PDF !", null, "HtmlToFile.pdf");
// convert HTML pages from URL to a PDF file
string htmlPageURL = "http://www.evopdf.com";
converter.ConvertUrlToFile(htmlPageURL, "UrlToFile.pdf");
using EvoPdf;
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert the HTML string to a PDF file
converter.ConvertHtmlToFile("<b>Hello World</b> from EVO PDF !", null, "HtmlToFile.pdf");
// convert HTML pages from URL to a PDF file
string htmlPageURL = "http://www.evopdf.com";
converter.ConvertUrlToFile(htmlPageURL, "UrlToFile.pdf");
Imports EvoPdf
' create the converter object in your code where you want to run conversion
Private converter As New HtmlToPdfConverter()
' convert the HTML string to a PDF file
converter.ConvertHtmlToFile("<b>Hello World</b> from EVO PDF !", Nothing, "HtmlToFile.pdf")
' convert HTML pages from URL to a PDF file
Dim htmlPageURL As String = "http://www.evopdf.com"
converter.ConvertUrlToFile(htmlPageURL, "UrlToFile.pdf")
HTML 转换为 PDF是一个常见的与PDF相关的任务,正如您在上述代码示例中所看到的,IronPDF和EvoPdf都可以轻松处理此工作。 IronPDF 通过其现代化的网络支持提供了像素完美的HTML内容渲染,因此您只需几行代码即可创建PDF文档,同时保持原始渲染质量。
IronPDF:
using IronPdf;
using System;
// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;
// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
using IronPdf;
using System;
// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;
// Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
Imports IronPdf
Imports System
' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")
' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now
' Edit file security settings
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
' change or set the document encryption password
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")
EvoPdf:
PdfSecurityOptions securityOptions = new PdfSecurityOptions();
securityOptions.CanAssembleDocument = canAssembleDocument;
securityOptions.CanCopyContent = canCopyContent;
securityOptions.CanEditAnnotations = canEditAnnotations;
securityOptions.CanEditContent = canEditContent;
securityOptions.CanFillFormFields = canFillFormFields;
securityOptions.CanPrint = canPrint;
securityOptions.KeySize = keySize;
securityOptions.UserPassword = userPassword;
securityOptions.OwnerPassword = ownerPassword;
PdfSecurityManager securityManager = new PdfSecurityManager(securityOptions);
if (removeSecurity)
securityManager.SaveUnSecuredPdfToFile(srcPdfFile, outFile, removeSecurityPswd);
else
securityManager.SaveSecuredPdfToFile(srcPdfFile, outFile);
PdfSecurityOptions securityOptions = new PdfSecurityOptions();
securityOptions.CanAssembleDocument = canAssembleDocument;
securityOptions.CanCopyContent = canCopyContent;
securityOptions.CanEditAnnotations = canEditAnnotations;
securityOptions.CanEditContent = canEditContent;
securityOptions.CanFillFormFields = canFillFormFields;
securityOptions.CanPrint = canPrint;
securityOptions.KeySize = keySize;
securityOptions.UserPassword = userPassword;
securityOptions.OwnerPassword = ownerPassword;
PdfSecurityManager securityManager = new PdfSecurityManager(securityOptions);
if (removeSecurity)
securityManager.SaveUnSecuredPdfToFile(srcPdfFile, outFile, removeSecurityPswd);
else
securityManager.SaveSecuredPdfToFile(srcPdfFile, outFile);
Dim securityOptions As New PdfSecurityOptions()
securityOptions.CanAssembleDocument = canAssembleDocument
securityOptions.CanCopyContent = canCopyContent
securityOptions.CanEditAnnotations = canEditAnnotations
securityOptions.CanEditContent = canEditContent
securityOptions.CanFillFormFields = canFillFormFields
securityOptions.CanPrint = canPrint
securityOptions.KeySize = keySize
securityOptions.UserPassword = userPassword
securityOptions.OwnerPassword = ownerPassword
Dim securityManager As New PdfSecurityManager(securityOptions)
If removeSecurity Then
securityManager.SaveUnSecuredPdfToFile(srcPdfFile, outFile, removeSecurityPswd)
Else
securityManager.SaveSecuredPdfToFile(srcPdfFile, outFile)
End If
IronPDF 提供了一个全面的 API 用于管理加密设置,同时让您对流程和各种安全设置进行全面控制。 EvoPdf 的加密工具在过程控制方面提供了类似的水平,使其成为 PDF 加密的另一个有力竞争者。
IronPDF:
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");
pdf.SaveAs("redacted.pdf");
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");
pdf.SaveAs("redacted.pdf");
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")
' Redact 'are' phrase from all pages
pdf.RedactTextOnAllPages("are")
pdf.SaveAs("redacted.pdf")
EvoPdf:缺乏内置文本编辑支持。
IronPDF为您提供强大的PDF功能。编辑工具能够在短短几行代码中从您的PDF文件中编辑指定内容。 另一方面,EvoPdf 不提供任何内置的 PDF 涂黑工具。
IronPDF:
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");
// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);
// Create PdfSignature object
var sig = new PdfSignature(cert);
// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>foo</h1>");
// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);
// Create PdfSignature object
var sig = new PdfSignature(cert);
// Sign PDF document
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>foo</h1>")
' Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
Private cert As New X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable)
' Create PdfSignature object
Private sig = New PdfSignature(cert)
' Sign PDF document
pdf.Sign(sig)
pdf.SaveAs("signed.pdf")
EvoPdf:
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
Document pdfDocument = null;
try
{
string htmlWithDigitalSignatureMarker = htmlStringTextBox.Text;
string baseUrl = baseUrlTextBox.Text;
// Convert a HTML string with a marker for digital signature to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithDigitalSignatureMarker, baseUrl);
// Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties
HtmlElementMapping digitalSignatureMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element");
if (digitalSignatureMapping != null)
{
PdfPage digitalSignaturePage = digitalSignatureMapping.PdfRectangles[0].PdfPage;
RectangleF digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle;
string certificateFilePath = Server.MapPath("~/DemoAppFiles/Input/Certificates/evopdf.pfx");
// Get the certificate from password protected PFX file
DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf");
DigitalCertificate certificate = certificates[0];
// Create the digital signature
DigitalSignatureElement signature = new DigitalSignatureElement(digitalSignatureRectangle, certificate);
signature.Reason = "Protect the document from unwanted changes";
signature.ContactInfo = "The contact email is support@evopdf.com";
signature.Location = "Development server";
digitalSignaturePage.AddElement(signature);
}
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Digital_Signatures.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
if (pdfDocument != null)
pdfDocument.Close();
}
}
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
Document pdfDocument = null;
try
{
string htmlWithDigitalSignatureMarker = htmlStringTextBox.Text;
string baseUrl = baseUrlTextBox.Text;
// Convert a HTML string with a marker for digital signature to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithDigitalSignatureMarker, baseUrl);
// Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties
HtmlElementMapping digitalSignatureMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element");
if (digitalSignatureMapping != null)
{
PdfPage digitalSignaturePage = digitalSignatureMapping.PdfRectangles[0].PdfPage;
RectangleF digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle;
string certificateFilePath = Server.MapPath("~/DemoAppFiles/Input/Certificates/evopdf.pfx");
// Get the certificate from password protected PFX file
DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf");
DigitalCertificate certificate = certificates[0];
// Create the digital signature
DigitalSignatureElement signature = new DigitalSignatureElement(digitalSignatureRectangle, certificate);
signature.Reason = "Protect the document from unwanted changes";
signature.ContactInfo = "The contact email is support@evopdf.com";
signature.Location = "Development server";
digitalSignaturePage.AddElement(signature);
}
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Digital_Signatures.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
if (pdfDocument != null)
pdfDocument.Close();
}
}
Protected Sub convertToPdfButton_Click(ByVal sender As Object, ByVal e As EventArgs)
' Create a HTML to PDF converter object with default settings
Dim htmlToPdfConverter As New HtmlToPdfConverter()
' Set license key received after purchase to use the converter in licensed mode
' Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="
Dim pdfDocument As Document = Nothing
Try
Dim htmlWithDigitalSignatureMarker As String = htmlStringTextBox.Text
Dim baseUrl As String = baseUrlTextBox.Text
' Convert a HTML string with a marker for digital signature to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithDigitalSignatureMarker, baseUrl)
' Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties
Dim digitalSignatureMapping As HtmlElementMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element")
If digitalSignatureMapping IsNot Nothing Then
Dim digitalSignaturePage As PdfPage = digitalSignatureMapping.PdfRectangles(0).PdfPage
Dim digitalSignatureRectangle As RectangleF = digitalSignatureMapping.PdfRectangles(0).Rectangle
Dim certificateFilePath As String = Server.MapPath("~/DemoAppFiles/Input/Certificates/evopdf.pfx")
' Get the certificate from password protected PFX file
Dim certificates As DigitalCertificatesCollection = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf")
Dim certificate As DigitalCertificate = certificates(0)
' Create the digital signature
Dim signature As New DigitalSignatureElement(digitalSignatureRectangle, certificate)
signature.Reason = "Protect the document from unwanted changes"
signature.ContactInfo = "The contact email is support@evopdf.com"
signature.Location = "Development server"
digitalSignaturePage.AddElement(signature)
End If
' Save the PDF document in a memory buffer
Dim outPdfBuffer() As Byte = pdfDocument.Save()
' Send the PDF as response to browser
' Set response content type
Response.AddHeader("Content-Type", "application/pdf")
' Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Digital_Signatures.pdf; size={0}", outPdfBuffer.Length.ToString()))
' Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer)
' End the HTTP response and stop the current page processing
Response.End()
Finally
' Close the PDF document
If pdfDocument IsNot Nothing Then
pdfDocument.Close()
End If
End Try
End Sub
IronPDF 提供了一个强大的 API 用于应用数字签名到您的PDF文件,同时保持过程简单易懂。 EvoPdf 提供基本的签名支持,但缺乏 IronPDF 提供的广泛选项,同时采用手动和更复杂的方法。
IronPDF:
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("<h2 style='color:red'>SAMPLE</h2>", 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("<h2 style='color:red'>SAMPLE</h2>", 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("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")
EvoPdf:
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
Document pdfDocument = null;
try
{
// Convert a HTML page to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);
// Get the stamp width and height
float stampWidth = float.Parse(stampWidthTextBox.Text);
float stampHeight = float.Parse(stampHeightTextBox.Text);
// Center the stamp at the top of PDF page
float stampXLocation = (pdfDocument.Pages[0].ClientRectangle.Width - stampWidth) / 2;
float stampYLocation = 0;
RectangleF stampRectangle = new RectangleF(stampXLocation, stampYLocation, stampWidth, stampHeight);
// Create the stamp template to be repeated in each PDF page
Template stampTemplate = pdfDocument.AddTemplate(stampRectangle);
// Create the HTML element to add in stamp template
HtmlToPdfElement stampHtmlElement = new HtmlToPdfElement(htmlStringTextBox.Text, baseUrlTextBox.Text);
// Set the HTML viewer width for the HTML added in stamp
stampHtmlElement.HtmlViewerWidth = 600;
// Fit the HTML content in stamp template
stampHtmlElement.FitWidth = true;
stampHtmlElement.FitHeight = true;
// Add HTML to stamp template
stampTemplate.AddElement(stampHtmlElement);
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Watermarks_and_Stamps.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
if (pdfDocument != null)
pdfDocument.Close();
}
}
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
Document pdfDocument = null;
try
{
// Convert a HTML page to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);
// Get the stamp width and height
float stampWidth = float.Parse(stampWidthTextBox.Text);
float stampHeight = float.Parse(stampHeightTextBox.Text);
// Center the stamp at the top of PDF page
float stampXLocation = (pdfDocument.Pages[0].ClientRectangle.Width - stampWidth) / 2;
float stampYLocation = 0;
RectangleF stampRectangle = new RectangleF(stampXLocation, stampYLocation, stampWidth, stampHeight);
// Create the stamp template to be repeated in each PDF page
Template stampTemplate = pdfDocument.AddTemplate(stampRectangle);
// Create the HTML element to add in stamp template
HtmlToPdfElement stampHtmlElement = new HtmlToPdfElement(htmlStringTextBox.Text, baseUrlTextBox.Text);
// Set the HTML viewer width for the HTML added in stamp
stampHtmlElement.HtmlViewerWidth = 600;
// Fit the HTML content in stamp template
stampHtmlElement.FitWidth = true;
stampHtmlElement.FitHeight = true;
// Add HTML to stamp template
stampTemplate.AddElement(stampHtmlElement);
// Save the PDF document in a memory buffer
byte[] outPdfBuffer = pdfDocument.Save();
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Watermarks_and_Stamps.pdf; size={0}", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
finally
{
// Close the PDF document
if (pdfDocument != null)
pdfDocument.Close();
}
}
Protected Sub convertToPdfButton_Click(ByVal sender As Object, ByVal e As EventArgs)
' Create a HTML to PDF converter object with default settings
Dim htmlToPdfConverter As New HtmlToPdfConverter()
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="
Dim pdfDocument As Document = Nothing
Try
' Convert a HTML page to a PDF document object
pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text)
' Get the stamp width and height
Dim stampWidth As Single = Single.Parse(stampWidthTextBox.Text)
Dim stampHeight As Single = Single.Parse(stampHeightTextBox.Text)
' Center the stamp at the top of PDF page
Dim stampXLocation As Single = (pdfDocument.Pages(0).ClientRectangle.Width - stampWidth) / 2
Dim stampYLocation As Single = 0
Dim stampRectangle As New RectangleF(stampXLocation, stampYLocation, stampWidth, stampHeight)
' Create the stamp template to be repeated in each PDF page
Dim stampTemplate As Template = pdfDocument.AddTemplate(stampRectangle)
' Create the HTML element to add in stamp template
Dim stampHtmlElement As New HtmlToPdfElement(htmlStringTextBox.Text, baseUrlTextBox.Text)
' Set the HTML viewer width for the HTML added in stamp
stampHtmlElement.HtmlViewerWidth = 600
' Fit the HTML content in stamp template
stampHtmlElement.FitWidth = True
stampHtmlElement.FitHeight = True
' Add HTML to stamp template
stampTemplate.AddElement(stampHtmlElement)
' Save the PDF document in a memory buffer
Dim outPdfBuffer() As Byte = pdfDocument.Save()
' Send the PDF as response to browser
' Set response content type
Response.AddHeader("Content-Type", "application/pdf")
' Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Watermarks_and_Stamps.pdf; size={0}", outPdfBuffer.Length.ToString()))
' Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer)
' End the HTTP response and stop the current page processing
Response.End()
Finally
' Close the PDF document
If pdfDocument IsNot Nothing Then
pdfDocument.Close()
End If
End Try
End Sub
IronPDF提供简洁而强大的PDF水印工具,使您可以轻松地将自定义水印应用于PDF文件,几乎无需设置。另一方面,EvoPdf需要投入相当多的精力来设置水印工具,使其成为一个较不简化的选项。
IronPDF:
文本印章:
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create text stamper
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create text stamper
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create text stamper
Private textStamper As New TextStamper() With {
.Text = "Text Stamper!",
.FontFamily = "Bungee Spice",
.UseGoogleFont = True,
.FontSize = 30,
.IsBold = True,
.IsItalic = True,
.VerticalAlignment = VerticalAlignment.Top
}
' Stamp the text stamper
pdf.ApplyStamp(textStamper)
pdf.SaveAs("stampText.pdf")
图像戳记器:
using IronPdf;
using IronPdf.Editing;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
using IronPdf;
using IronPdf.Editing;
using System;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top,
};
// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
Imports IronPdf
Imports IronPdf.Editing
Imports System
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create image stamper
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}
' Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0)
pdf.SaveAs("stampImage.pdf")
EvoPdf:对图像和文本标记的支持有限,使用与其水印功能相同的工具。
IronPDF提供详细且灵活的方法,用于将文本和图像印章添加到PDF中,其冲压工具易于使用,且实现所需代码不多。 在将文本添加到PDF页面之前,EvoPdf需要更多的设置。
DOCX转PDF C#
IronPDF:
using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
Imports IronPdf
' Instantiate Renderer
Private renderer As New DocxToPdfRenderer()
' Render from DOCX file
Private pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")
EvoPdf:你需要使用Evo Work to PDF转换库来将DOCX文件转换为PDF格式。
IronPDF提供直观的API用于DOCX 转换为 PDF,使处理不同的文档类型更容易。使用EvoPdf时,您需要确保安装了Evo Word to PDF工具才能执行此任务。
要了解 IronPDF 提供的丰富功能集并查看其实际应用,请查看 IronPDF。如何操作指南深入探讨每个功能,探索其工作原理,并为您提供成为PDF专家所需的技能。
IronPDF拥有不同级别和购买许可证的附加功能。 开发者还可以购买Iron Suite让您以两个产品的价格访问Iron Software的所有产品。 如果您还没有准备好购买许可证,IronPDF提供一个免费试用这样您就可以在购买许可证之前探索其提供的所有功能。
IronSuite:您可以通过支付1,498美元获得所有Iron Software产品的访问权限,包括IronPDF, IronOCR, IronWord, IronXL, IronBarcode, IronQR, IronZIP, IronPrint和IronWebScraper.
EvoPdf 的许可基于两种模式:部署许可和公司许可。 两种选项均为永久许可,并在第一年提供技术支持和软件更新。
IronPDF以其全面、详细的文档和开发者支持而自豪。
PDF API 参考: 提供 API 参考,让您充分利用我们的工具所提供的功能。
documentation on our website.文献资料,并访问Iron Software YouTube频道.
IronPDF和EvoPdf都是为.NET开发人员提供的强大PDF库。 然而,IronPDF 广泛的功能集、强大的跨平台兼容性、灵活的许可选项以及出色的文档和支持,使其成为大多数开发项目更具吸引力的选择。 使用 IronPDF,您可以轻松执行任何与 PDF 相关的任务,并且拥有强大且丰富的功能集在手边。
EvoPdf 是一个不错的替代方案,特别适合那些专注于寻找 HTML 到 PDF 转换工具的人,并且不需要更高级库的多余功能,同时仍然可以通过投资完整的工具包来添加和删除功能。
您可以尝试 0 天免费试用 查看他们的可用功能。