在實際環境中測試
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
IronPDF和 EvoPdf 是兩個用於創建、編輯和管理 PDF 文件的著名 .NET 程式庫。 每個都有獨特的優勢和功能,專為在 .NET 平台上工作的開發者量身打造。 本文將深入比較這兩個庫,重點介紹它們的功能、兼容性、許可證、支持等。
希望在閱讀本文後,您能夠識別最適合您 PDF 需求的函式庫,並且如果您想要探索更多 PDF 函式庫選項,能夠進行自己的比較。
IronPDF是一個 .NET PDF 庫,允許開發人員以程式方式創建、編輯和操作 PDF 文件。 以其易於使用、廣泛兼容.NET版本以及能夠將HTML、ASPX和圖像文件轉換為PDF的能力而著稱,同時保持對原始內容的高度忠實度。 IronPDF 的廣泛文件記錄、強大的客戶支持及豐富的功能集,使其成為尋求將 PDF 功能整合到 .NET 應用程序中的開發者的首選。
EvoPdf 是另一個 .NET 函式庫,專為 HTML 到 PDF 轉換及其他 PDF 操作任務而設計。 它提供對 HTML 標籤、CSS、JavaScript 及其他現代網頁技術的高級支援,從而能夠從網頁內容生成高品質的 PDF 文件。 EvoPdf 因其渲染能力和對網頁標準的廣泛支持而受到讚賞,這使得它成為專注於網頁轉PDF轉換的開發人員的寶貴工具。
IronPDF 提供廣泛的跨平台兼容性,使其成為適用於各種環境的多功能工具:
作業系統和處理器: 支援多種不同的作業系統和處理器,包括 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 中新增文字和圖像印章,這個功能的沖壓工具容易使用,且實現不需要太多的程式碼。 EvoPdf 在將文字加蓋到您的 PDF 頁面之前需要進行更多設定。
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擁有不同的等級和額外功能可供購買許可證。 開發人員還可以購買IronSuite這使您能以兩個產品的價格訪問所有 Iron Software 的產品。 如果您還沒準備好購買許可證,IronPDF 提供一個免費試用因此,您可以在承諾購買許可證之前探索其提供的所有功能。
IronSuite:花費 $1,498,您可以獲得所有 Iron Software 產品的訪問權限,包括IronPDF, IronOCR, IronWord, IronXL, IronBarcode, IronQR, IronZIP, IronPrint,和IronWebScraper.
EvoPdf的授權基於兩種模式:部署授權和公司授權。 這兩個選項都提供永久許可,並在第一年提供技術支援和軟體更新。
IronPDF自豪於其廣泛且詳細的文件和開發者支持。
PDF API 參考:提供 API 參考,讓您充分發揮我們工具所提供的功能。
如需更多資訊,請查看 IronPDF 的廣泛內容文檔, 並造訪Iron Software YouTube 頻道.
IronPDF和EvoPdf都是功能強大的PDF庫,適用於.NET開發人員。 然而,IronPDF 的廣泛功能集、強大的跨平台相容性、靈活的授權選擇,以及優秀的文件和支援,讓它成為大多數開發專案的一個更具吸引力的選擇。 使用 IronPDF,您可以輕鬆處理任何與 PDF 有關的任務,因為您隨時擁有強大且豐富的功能集。
EvoPdf 是一個穩固的替代方案,特別適合那些專門尋找專注於 HTML 到 PDF 轉換工具且不想要更高階庫附帶許多附加功能的人,同時仍然可以選擇通過購買完整工具包來添加和移除功能。
您可以嘗試使用 0 天免費試用 查看他們的可用功能。