在實際環境中測試
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
當您處理 PDF 文件時,選擇適合自己需求的工具是重要的第一步。您是在尋找僅僅將 HTML 內容轉換為 PDF 文件的工具嗎?還是您的 PDF 項目需要更複雜的工具,如加密和應用電子簽名?今天,我們將探討兩個 PDF 庫,IronPDF 和 SelectPdf,並研究如何使用這些庫來提升您的 PDF 工作區。
IronPDF 是為 .NET 生態系統中所有 PDF 相關任務提供一站式解決方案。它支持 HTML、CSS、JavaScript 以及多種圖像格式,因此非常適合用於基於 Web 的應用程序。IronPDF 擁有多種功能,如生成 PDF、編輯 PDF 或簽名和加密,是添加到您的工具組合中的極佳工具。
SelectPdf 提供靈活的 HTML 到 PDF 轉換器,適用於可在 .NET Framework 和 .NET Core 平台上運行的 .NET 應用程序。它提供了豐富的功能來創建 PDF 文件和操作現有的 PDF 文檔,這使得它適合於各種業務和個人場景。
IronPDF 支援多種平台,確保您能在偏好的環境中工作。以下是其相容性的一個概述:
.NET 版本:
(C#, VB.NET, F#)
.NET Core (8, 7, 6, 5, 和 3.1+)
.NET Framework (4.6.2+)
更多信息,請訪問 IronPDF 相容性.
.NET 版本:
有關 IronPDF 提供的功能的詳細信息,請訪問 IronPDF 功能.
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 字符串,IronPDF 都能通過使用 ChromePdfRenderer 和支持現代網頁標準來提供高保真度的 PDF 文件。使用 IronPDF,您可以轉換 HTML轉PDF 使用幾行代碼。SelectPdf 的 HTML 到 PDF 轉換工具簡潔且實施迅速,但可能無法產生同樣高質量的輸出。pdf. 轉換
如果您想了解有關 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
// 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");
<br>
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");
<br>
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")
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'<br>
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文件進行簽名非常容易。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");
<br>
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");
<br>
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")
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'<br>
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 文件上。應用文字或圖片戳記的方法類似於 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");
<br>
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");
<br>
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")
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'<br>
SelectPdf:
SelectPdf不支持直接將DOCX轉換為PDF。
IronPDF支持直接轉換 DOCX 檔案轉 PDF透過這個功能,您只需幾行程式碼即可將DOCX轉換為PDF,並且不會失去檔案的任何品質。然而,SelectPdf沒有提供內建的DOCX到PDF的支援。
如需了解更多有關IronPDF的DOCX轉PDF功能,請務必查看 操作指南 此主題的指南。
欲了解詳細的程式碼範例,請訪問 IronPDF 範例.
IronPDF 具有不同层级和额外功能的许可证可供购买。开发人员还可以购买 IronSuite ,讓您以兩個產品的價格獲得所有IronSoftware的產品。如果您還沒準備購買授權,IronPDF提供 免費試用 持續 30 天。
SelectPdf 提供一系列包含一年的維護計劃的永久性許可級別。
IronPDF 在提供廣泛的文件及支援方面表現優異:
想了解更多資訊,請參考 IronPDF 的詳細資訊。 文檔, 並造訪 IronSoftware YouTube 頻道.
擁有合適的PDF庫來滿足您的PDF專案需求在處理PDF時至關重要。今天我們看到了IronPDF和SelectPdf的實際應用,並仔細查看了這兩個庫。SelectPdf提供了一系列穩固的功能來處理PDF,但其中許多功能可能比IronPDF更需要工作來實現。
IronPDF突顯了其作為一個多功能且全面的解決方案,適合需要強大PDF功能的.NET開發人員。其豐富的功能、與現代.NET框架的兼容性以及出色的支持,使其成為開發人員工具包中的強大工具。