在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
在处理 PDF 文档时,选择适合自己需要的工具是重要的第一步。您是否只是想将 HTML 内容转换为 PDF 文档? 或者您的 PDF 项目需要更复杂的工具,如加密和应用数字签名? 今天,我们将介绍 IronPDF 和 SelectPdf 这两个 PDF 库,并研究如何使用这些库来提升您的 PDF 工作空间。
了解有关 IronPDF 的更多信息在.NET 生态系统中,"PDF "旨在成为所有 PDF 相关任务的一站式解决方案。 它支持 HTML、CSS、JavaScript 以及多种图像格式,因此对基于网络的应用程序具有极强的适应性。 IronPDF 具有生成 PDF、编辑 PDF 或签名和加密等多种功能,是一款值得添加到您的工具库中的好工具。
SelectPdf 为 .NET 应用程序提供了灵活的 HTML 到 PDF 转换器,可在 .NET Framework 和 .NET Core 平台上运行。 它提供了创建 PDF 文件和处理现有 PDF 文档的丰富功能,因此适用于各种业务和个人场景。
IronPDF支持多种平台,确保您可以在首选环境中工作。 以下是其兼容性的分解:
.NET 版本:
-(C#, VB.NET, F#)
.NET Core(8、7、6、5 和 3.1+)
操作系统和处理器: 支持多种不同的操作系统和处理器,包括Windows、Mac、Linux、x64、x86、ARM。
有关更多信息,请访问IronPDF 兼容性详细信息.
.NET 版本:
.NET Framework 4.0 以上
PDF 编辑功能: 使用 IronPDF,您可以轻松编辑现有文档。 IronPDF 提供的编辑功能包括添加页眉和页脚、在 PDF 页面上印制文本和图像、合并和拆分 PDF 文档、在 PDF 上添加自定义水印以及处理 PDF 表单。
请访问以下网址以获取有关IronPDF提供的功能的详细信息:IronPDF 高级功能.
<table>
<thead>
<tr>
<th>功能</th>
<th>IronPDF 代码示例</th>
<th>SelectPdf 代码示例</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pdf 转换</td>
<td>
<pre><code class="language-csharp">
var Renderer = new IronPdf.ChromePdfRenderer();
var PDFDocument = Renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");
PDFDocument.SaveAs("HtmlToPdf.pdf");
</code></pre>
</td>
<td>
<pre><code class="language-csharp">
var converter = new HtmlToPdf();
var doc = converter.ConvertHtmlString("<h1>Hello, World!</h1>");
doc.Save("HtmlToPdf.pdf");
</code></pre>
</td>
</tr>
<tr>
<td>添加水印</td>
<td>
<pre><code class="language-csharp">
var PDFDocument = PdfDocument.FromFile("example.pdf");
var StampedPdf = PDFDocument.StampPDF("Confidential", PageNumbering.Normal, FontSize: 50, opacity: 50);
StampedPdf.SaveAs("Watermarked.pdf");
</code></pre>
</td>
<td>
<pre><code class="language-csharp">
var doc = new PdfDocument();
var watermark = new PdfTextSection(10, 10, "Confidential", new Font("Arial", 50));
watermark.Opacity = 0.5;
doc.Add(watermark);
doc.Save("Watermarked.pdf");
</code></pre>
</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>功能</th>
<th>IronPDF 代码示例</th>
<th>SelectPdf 代码示例</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pdf 转换</td>
<td>
<pre><code class="language-csharp">
var Renderer = new IronPdf.ChromePdfRenderer();
var PDFDocument = Renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");
PDFDocument.SaveAs("HtmlToPdf.pdf");
</code></pre>
</td>
<td>
<pre><code class="language-csharp">
var converter = new HtmlToPdf();
var doc = converter.ConvertHtmlString("<h1>Hello, World!</h1>");
doc.Save("HtmlToPdf.pdf");
</code></pre>
</td>
</tr>
<tr>
<td>添加水印</td>
<td>
<pre><code class="language-csharp">
var PDFDocument = PdfDocument.FromFile("example.pdf");
var StampedPdf = PDFDocument.StampPDF("Confidential", PageNumbering.Normal, FontSize: 50, opacity: 50);
StampedPdf.SaveAs("Watermarked.pdf");
</code></pre>
</td>
<td>
<pre><code class="language-csharp">
var doc = new PdfDocument();
var watermark = new PdfTextSection(10, 10, "Confidential", new Font("Arial", 50));
watermark.Opacity = 0.5;
doc.Add(watermark);
doc.Save("Watermarked.pdf");
</code></pre>
</td>
</tr>
</tbody>
</table>
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");
// Advanced Example with HTML Assets
// Load external html assets: images, CSS and JavaScript.
// An optional BasePath 'c:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"c:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.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");
// Advanced Example with HTML Assets
// Load external html assets: images, CSS and JavaScript.
// An optional BasePath 'c:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"c:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
SelectPdf:
// instantiate an HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();
// create a new pdf document converting an url
PdfDocument doc = converter.ConvertUrl(url);
// save pdf document
doc.Save(file);
// close pdf document
doc.Close();
// instantiate an HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();
// create a new pdf document converting an url
PdfDocument doc = converter.ConvertUrl(url);
// save pdf document
doc.Save(file);
// close pdf document
doc.Close();
IRON VB CONVERTER ERROR developers@ironsoftware.com
无论您是要将多个网页转换为同一个 PDF 文档,还是要将单个 HTML 字符串转换为 PDF 文档,IronPDF 都能提供高保真的 PDF 文件,这要归功于它使用了ChromePdfRenderer并支持现代网络标准。 使用 IronPDF,您可以转换高保真 HTML 到 PDF只需几行代码。 SelectPdf 的 HTML 到 PDF 转换工具简洁明了、实施快捷,但可能无法产生同样高质量的输出。
如果您想了解有关 IronPDF HTML 到 PDF 转换工具的更多信息,那么请查看我们方便的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
// 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;
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
// 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;
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
' 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
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")
SelectPdf:
// set document passwords
doc.Security.OwnerPassword = "test1";
doc.Security.UserPassword = "test2";
//set document permissions
doc.Security.CanAssembleDocument = false;
doc.Security.CanCopyContent = true;
doc.Security.CanEditAnnotations = true;
doc.Security.CanEditContent = true;
doc.Security.CanFillFormFields = true;
doc.Security.CanPrint = true;
// set document passwords
doc.Security.OwnerPassword = "test1";
doc.Security.UserPassword = "test2";
//set document permissions
doc.Security.CanAssembleDocument = false;
doc.Security.CanCopyContent = true;
doc.Security.CanEditAnnotations = true;
doc.Security.CanEditContent = true;
doc.Security.CanFillFormFields = true;
doc.Security.CanPrint = true;
' set document passwords
doc.Security.OwnerPassword = "test1"
doc.Security.UserPassword = "test2"
'set document permissions
doc.Security.CanAssembleDocument = False
doc.Security.CanCopyContent = True
doc.Security.CanEditAnnotations = True
doc.Security.CanEditContent = True
doc.Security.CanFillFormFields = True
doc.Security.CanPrint = True
当您在寻找高效加密您的 PDF此外,IronPDF 和 SelectPdf 都提供内置加密工具。 IronPDF 的加密功能非常广泛,可以让您对各种安全设置进行大量控制,同时使用起来仍然简单明了。 SelectPdf 的加密功能简洁明了,易于在您的项目中实施。
有关在 PDF 文件中添加密码和权限的更多信息,请访问 IronPDF 有用的添加密码和权限指南.
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")
SelectPdf:
SelectPdf 不支持直接编辑。
IronPDF 提供了一种简洁而强大的 PDF重反应工具因此,我们需要一个能用几行代码编辑指定内容的翻译工具。 另一方面,SelectPdf 缺乏任何内置的编辑功能。
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")
SelectPdf:
// create a new pdf document
PdfDocument doc = new PdfDocument();
// add a new page to the document
PdfPage page = doc.AddPage();
// get image path
// the image will be used to display the digital signature over it
string imgFile = Server.MapPath("~/files/logo.png");
// get certificate path
string certFile = Server.MapPath("~/files/selectpdf.pfx");
// define a rendering result object
PdfRenderingResult result;
// create image element from file path
PdfImageElement img = new PdfImageElement(0, 0, imgFile);
result = page.Add(img);
// get the #PKCS12 certificate from file
PdfDigitalCertificatesCollection certificates =
PdfDigitalCertificatesStore.GetCertificates(certFile, "selectpdf");
PdfDigitalCertificate certificate = certificates[0];
// create the digital signature object
PdfDigitalSignatureElement signature =
new PdfDigitalSignatureElement(result.PdfPageLastRectangle, certificate);
signature.Reason = "SelectPdf";
signature.ContactInfo = "SelectPdf";
signature.Location = "SelectPdf";
page.Add(signature);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
// create a new pdf document
PdfDocument doc = new PdfDocument();
// add a new page to the document
PdfPage page = doc.AddPage();
// get image path
// the image will be used to display the digital signature over it
string imgFile = Server.MapPath("~/files/logo.png");
// get certificate path
string certFile = Server.MapPath("~/files/selectpdf.pfx");
// define a rendering result object
PdfRenderingResult result;
// create image element from file path
PdfImageElement img = new PdfImageElement(0, 0, imgFile);
result = page.Add(img);
// get the #PKCS12 certificate from file
PdfDigitalCertificatesCollection certificates =
PdfDigitalCertificatesStore.GetCertificates(certFile, "selectpdf");
PdfDigitalCertificate certificate = certificates[0];
// create the digital signature object
PdfDigitalSignatureElement signature =
new PdfDigitalSignatureElement(result.PdfPageLastRectangle, certificate);
signature.Reason = "SelectPdf";
signature.ContactInfo = "SelectPdf";
signature.Location = "SelectPdf";
page.Add(signature);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
' create a new pdf document
Dim doc As New PdfDocument()
' add a new page to the document
Dim page As PdfPage = doc.AddPage()
' get image path
' the image will be used to display the digital signature over it
Dim imgFile As String = Server.MapPath("~/files/logo.png")
' get certificate path
Dim certFile As String = Server.MapPath("~/files/selectpdf.pfx")
' define a rendering result object
Dim result As PdfRenderingResult
' create image element from file path
Dim img As New PdfImageElement(0, 0, imgFile)
result = page.Add(img)
' get the #PKCS12 certificate from file
Dim certificates As PdfDigitalCertificatesCollection = PdfDigitalCertificatesStore.GetCertificates(certFile, "selectpdf")
Dim certificate As PdfDigitalCertificate = certificates(0)
' create the digital signature object
Dim signature As New PdfDigitalSignatureElement(result.PdfPageLastRectangle, certificate)
signature.Reason = "SelectPdf"
signature.ContactInfo = "SelectPdf"
signature.Location = "SelectPdf"
page.Add(signature)
' save pdf document
doc.Save(Response, False, "Sample.pdf")
' close pdf document
doc.Close()
使用IronPDF,可以应用轻松完成数字签名使用其简单、强大的 PDF 签名工具,您可以轻松地将 PDF 文件添加到您的 PDF 文件中。 SelectPdf 还可以对 PDF 应用数字签名,不过这需要更多的设置和更多的手动操作。
如果您想了解 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")
SelectPdf:
// create a new pdf document
PdfDocument doc = new PdfDocument();
// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 24;
// add a new page to the document
PdfPage page = doc.AddPage();
// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeLongText(), font);
page.Add(text);
// get image path
string imgFile = Server.MapPath("~/files/logo.png");
// watermark all pages - add a template containing an image
// to the bottom right of the page
// the image should repeat on all pdf pages automatically
// the template should be rendered behind the rest of the page elements
PdfTemplate template = doc.AddTemplate(doc.Pages[0].ClientRectangle);
PdfImageElement img = new PdfImageElement(
doc.Pages[0].ClientRectangle.Width - 300,
doc.Pages[0].ClientRectangle.Height - 150, imgFile);
img.Transparency = 50;
template.Background = true;
template.Add(img);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
// create a new pdf document
PdfDocument doc = new PdfDocument();
// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 24;
// add a new page to the document
PdfPage page = doc.AddPage();
// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeLongText(), font);
page.Add(text);
// get image path
string imgFile = Server.MapPath("~/files/logo.png");
// watermark all pages - add a template containing an image
// to the bottom right of the page
// the image should repeat on all pdf pages automatically
// the template should be rendered behind the rest of the page elements
PdfTemplate template = doc.AddTemplate(doc.Pages[0].ClientRectangle);
PdfImageElement img = new PdfImageElement(
doc.Pages[0].ClientRectangle.Width - 300,
doc.Pages[0].ClientRectangle.Height - 150, imgFile);
img.Transparency = 50;
template.Background = true;
template.Add(img);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
' create a new pdf document
Dim doc As New PdfDocument()
' create a new pdf font
Dim font As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
font.Size = 24
' add a new page to the document
Dim page As PdfPage = doc.AddPage()
' create a new text element and add it to the page
Dim text As New PdfTextElement(0, 0, Helper.SomeLongText(), font)
page.Add(text)
' get image path
Dim imgFile As String = Server.MapPath("~/files/logo.png")
' watermark all pages - add a template containing an image
' to the bottom right of the page
' the image should repeat on all pdf pages automatically
' the template should be rendered behind the rest of the page elements
Dim template As PdfTemplate = doc.AddTemplate(doc.Pages(0).ClientRectangle)
Dim img As New PdfImageElement(doc.Pages(0).ClientRectangle.Width - 300, doc.Pages(0).ClientRectangle.Height - 150, imgFile)
img.Transparency = 50
template.Background = True
template.Add(img)
' save pdf document
doc.Save(Response, False, "Sample.pdf")
' close pdf document
doc.Close()
IronPDF 的内置水印工具水印 "使用 HTML 和 CSS,提供了一种在 PDF 页面上应用水印的简便方法,同时让您可以完全控制整个过程,而这一切只需使用几行代码即可完成。 SelectPdf 也有一个 PDF 水印工具,您可以用它为 PDF 添加自定义水印,但是这个过程比较长,而且可能不那么容易实现。
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");
// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("/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;
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");
// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("/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
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")
' Create image stamper
Dim imageStamper As New ImageStamper(New Uri("/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}
' Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0)
pdf.SaveAs("stampImage.pdf")
SelectPdf:
// create a new pdf document
PdfDocument doc = new PdfDocument();
// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 24;
// add a new page to the document
PdfPage page = doc.AddPage();
// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeLongText(), font);
page.Add(text);
// get image path
string imgFile = Server.MapPath("~/files/logo.png");
// stamp all pages - add a template containing an image to the bottom right of
// the page the image should repeat on all pdf pages automatically
PdfTemplate template = doc.AddTemplate(doc.Pages[0].ClientRectangle);
PdfImageElement img = new PdfImageElement(
doc.Pages[0].ClientRectangle.Width - 300,
doc.Pages[0].ClientRectangle.Height - 150, imgFile);
template.Add(img);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
// create a new pdf document
PdfDocument doc = new PdfDocument();
// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 24;
// add a new page to the document
PdfPage page = doc.AddPage();
// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeLongText(), font);
page.Add(text);
// get image path
string imgFile = Server.MapPath("~/files/logo.png");
// stamp all pages - add a template containing an image to the bottom right of
// the page the image should repeat on all pdf pages automatically
PdfTemplate template = doc.AddTemplate(doc.Pages[0].ClientRectangle);
PdfImageElement img = new PdfImageElement(
doc.Pages[0].ClientRectangle.Width - 300,
doc.Pages[0].ClientRectangle.Height - 150, imgFile);
template.Add(img);
// save pdf document
doc.Save(Response, false, "Sample.pdf");
// close pdf document
doc.Close();
' create a new pdf document
Dim doc As New PdfDocument()
' create a new pdf font
Dim font As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
font.Size = 24
' add a new page to the document
Dim page As PdfPage = doc.AddPage()
' create a new text element and add it to the page
Dim text As New PdfTextElement(0, 0, Helper.SomeLongText(), font)
page.Add(text)
' get image path
Dim imgFile As String = Server.MapPath("~/files/logo.png")
' stamp all pages - add a template containing an image to the bottom right of
' the page the image should repeat on all pdf pages automatically
Dim template As PdfTemplate = doc.AddTemplate(doc.Pages(0).ClientRectangle)
Dim img As New PdfImageElement(doc.Pages(0).ClientRectangle.Width - 300, doc.Pages(0).ClientRectangle.Height - 150, imgFile)
template.Add(img)
' save pdf document
doc.Save(Response, False, "Sample.pdf")
' close pdf document
doc.Close()
IronPDF 提供了一个强大的工具用于在 PDF 上印制文本和图像您的 PDF 文档。 应用文本或图像标记的方法类似 HTML 和 CSS,这意味着您可以完全控制标记过程。 SelectPdf 的方法时间较长,过程中涉及较多的手工工作。
如果您想了解有关 IronPDF 冲压工具的更多信息,请务必查看其方便的冲压文本和图像指南.
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")
SelectPdf:
SelectPdf 不支持 DOCX 到 PDF 的直接转换。
IronPDF 支持以下语言的直接转换DOCX 文件转 PDF. 有了这项功能,您只需几行字就能将 DOCX 转换为 PDF,而且不会损失文件的任何质量。 然而,SelectPdf 并不提供 DOCX 到 PDF 的内置支持。
有关 IronPDF DOCX 至 PDF 转换功能的更多信息,请务必查看DOCX 到 PDF 转换指南.
有关详细的代码示例,请访问IronPDF 示例页面.
IronPDF 授权和定价拥有不同级别和购买许可证的附加功能。 开发者也可以购买Iron Suite它使您可以仅以两个产品的价格访问IronSoftware的所有产品。 如果您尚未准备购买许可证,IronPDF提供了一种免费试用持续30天。
IronSuite:花费 $1,498,您将获得所有Iron Software产品的访问权,包括IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint和IronWebScraper。
SelectPdf 提供一系列永久许可级别,均包含一年维护计划。
IronPDF在提供广泛文档和支持方面表现出色:
定期更新:每月产品更新,确保具备最新功能和安全补丁。
documentation on our website.文档库,并访问IronSoftware YouTube频道.
在处理 PDF 时,拥有满足 PDF 项目需求的合适 PDF 库至关重要。 今天,我们看到了 IronPdf 和 SelectPdf 的实际应用,并对这两个库进行了仔细了解。 SelectPdf 为处理 PDF 提供了一系列可靠的功能,但其中很多功能的实现可能要比 IronPDF 的对应功能花费更多的精力。
对于需要强大 PDF 功能的 .NET 开发人员来说,IronPDF 是一个多功能的综合解决方案。 其丰富的功能、与现代 .NET Framework 的兼容性以及出色的支持使其成为开发人员工具包中的强大工具。
您可以尝试 0 天免费试用 查看他们的可用功能。