var pdf = new IronPdf.PdfDocument("input.pdf");var stamper = new IronPdf.Editing.TextStamper(){Text = "Confidential",FontSize = 50,Opacity = 50,VerticalAlignment = IronPdf.Editing.VerticalAlignment.Middle,HorizontalAlignment = IronPdf.Editing.HorizontalAlignment.Center};pdf.ApplyStamp(stamper);pdf.SaveAs("stamped.pdf");
var pdf = new IronPdf.PdfDocument("input.pdf");
var stamper = new IronPdf.Editing.TextStamper()
{
Text = "Confidential",
FontSize = 50,
Opacity = 50,
VerticalAlignment = IronPdf.Editing.VerticalAlignment.Middle,
HorizontalAlignment = IronPdf.Editing.HorizontalAlignment.Center
};
pdf.ApplyStamp(stamper);
pdf.SaveAs("stamped.pdf");
using IronPdf;using IronPdf.Editing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");// Create text stamperTextStamper textStamper = new TextStamper(){Text = "Text Stamper!",FontFamily = "Bungee Spice",UseGoogleFont = true,FontSize = 30,IsBold = true,IsItalic = true,VerticalAlignment = VerticalAlignment.Top,};// Stamp the text stamperpdf.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");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create text stamperPrivate 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 stamperpdf.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 stamperImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")){VerticalAlignment = VerticalAlignment.Top,};// Stamp the image stamperpdf.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");
ImportsIronPdfImportsIronPdf.EditingImportsSystemPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create image stamperPrivate imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}' Stamp the image stamperpdf.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")
using IronPdf;using IronPdf.Editing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");// Create two text stampersTextStamper stamper1 = new TextStamper(){Text = "Text stamp 1",VerticalAlignment = VerticalAlignment.Top,HorizontalAlignment = HorizontalAlignment.Left,};TextStamper stamper2 = new TextStamper(){Text = "Text stamp 2",VerticalAlignment = VerticalAlignment.Top,HorizontalAlignment = HorizontalAlignment.Right,};Stamper[] stampersToApply = { stamper1, stamper2 };// Apply multiple stampspdf.ApplyMultipleStamps(stampersToApply);pdf.SaveAs("multipleStamps.pdf");
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create two text stampers
TextStamper stamper1 = new TextStamper()
{
Text = "Text stamp 1",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
TextStamper stamper2 = new TextStamper()
{
Text = "Text stamp 2",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Right,
};
Stamper[] stampersToApply = { stamper1, stamper2 };
// Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply);
pdf.SaveAs("multipleStamps.pdf");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create two text stampersPrivate stamper1 As New TextStamper() With { .Text = "Text stamp 1", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Left}Private stamper2 As New TextStamper() With { .Text = "Text stamp 2", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Right}Private stampersToApply() AsStamper = { stamper1, stamper2 }' Apply multiple stampspdf.ApplyMultipleStamps(stampersToApply)pdf.SaveAs("multipleStamps.pdf")
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create two text stampers
Private stamper1 As New TextStamper() With {
.Text = "Text stamp 1",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Left
}
Private stamper2 As New TextStamper() With {
.Text = "Text stamp 2",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Right
}
Private stampersToApply() As Stamper = { stamper1, stamper2 }
' Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply)
pdf.SaveAs("multipleStamps.pdf")
当印章重叠时会发生什么?
我可以混合使用不同类型的印章吗?
BarcodeStamper。 同时创建带有页眉、页脚、水印和识别码的复杂文档布局。
如何控制图章位置?
using 3x3 网格(横向三列,纵向三行)定义图章位置。 选择水平对齐方式:左对齐、居中对齐、右对齐。 选择垂直对齐方式:上、中、下。 调整水平和垂直偏移以实现精确定位。 请参见下图,以获得直观的说明。
使用VerticalOffset。 默认计量单位为百分比。 可用单位包括英寸、毫米、厘米、像素和点。 这样就可以实现精确定位,如在 PDF 文档中设置自定义页边距。
代码
using IronPdf.Editing;using System;// Create text stamperImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")){HorizontalAlignment = HorizontalAlignment.Center,VerticalAlignment = VerticalAlignment.Top, // Specify offsetsHorizontalOffset = new Length(10),VerticalOffset = new Length(10),};
using IronPdf.Editing;
using System;
// Create text stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
// Specify offsets
HorizontalOffset = new Length(10),
VerticalOffset = new Length(10),
};
ImportsIronPdf.EditingImportsSystem' Create text stamperPrivate imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With { .HorizontalAlignment = HorizontalAlignment.Center, .VerticalAlignment = VerticalAlignment.Top, .HorizontalOffset = New Length(10), .VerticalOffset = New Length(10)}
Imports IronPdf.Editing
Imports System
' Create text stamper
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {
.HorizontalAlignment = HorizontalAlignment.Center,
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalOffset = New Length(10),
.VerticalOffset = New Length(10)
}
我最喜欢的这种库是 IronPDF。它允许快速高效地操作 PDF 文件。它还具有许多有价值的功能,比如导出为 PDF/A 格式和数字签名 PDF 文档。
使用HtmlStamper类盖章文本和图像。 HtmlStamper渲染带有CSS样式的HTML设计,然后将其盖在PDF文档上。 HtmlBaseUrl属性指定HTML字符串资产(如CSS和图像文件)的基本URL。 这与 将 HTML 转换为 PDF 使用相同的渲染引擎。
代码
using IronPdf;using IronPdf.Editing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");// Create two text stampersTextStamper stamper1 = new TextStamper(){Text = "Text stamp 1",VerticalAlignment = VerticalAlignment.Top,HorizontalAlignment = HorizontalAlignment.Left,};TextStamper stamper2 = new TextStamper(){Text = "Text stamp 2",VerticalAlignment = VerticalAlignment.Top,HorizontalAlignment = HorizontalAlignment.Right,};Stamper[] stampersToApply = { stamper1, stamper2 };// Apply multiple stampspdf.ApplyMultipleStamps(stampersToApply);pdf.SaveAs("multipleStamps.pdf");
using IronPdf;
using IronPdf.Editing;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create two text stampers
TextStamper stamper1 = new TextStamper()
{
Text = "Text stamp 1",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
TextStamper stamper2 = new TextStamper()
{
Text = "Text stamp 2",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Right,
};
Stamper[] stampersToApply = { stamper1, stamper2 };
// Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply);
pdf.SaveAs("multipleStamps.pdf");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create two text stampersPrivate stamper1 As New TextStamper() With { .Text = "Text stamp 1", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Left}Private stamper2 As New TextStamper() With { .Text = "Text stamp 2", .VerticalAlignment = VerticalAlignment.Top, .HorizontalAlignment = HorizontalAlignment.Right}Private stampersToApply() AsStamper = { stamper1, stamper2 }' Apply multiple stampspdf.ApplyMultipleStamps(stampersToApply)pdf.SaveAs("multipleStamps.pdf")
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create two text stampers
Private stamper1 As New TextStamper() With {
.Text = "Text stamp 1",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Left
}
Private stamper2 As New TextStamper() With {
.Text = "Text stamp 2",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Right
}
Private stampersToApply() As Stamper = { stamper1, stamper2 }
' Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply)
pdf.SaveAs("multipleStamps.pdf")
using IronPdf;using IronPdf.Editing;ChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");// Create text stamperTextStamper textStamper = new TextStamper(){Text = "Text Stamper!",FontFamily = "Bungee Spice",UseGoogleFont = true,FontSize = 30,IsBold = true,IsItalic = true,VerticalAlignment = VerticalAlignment.Top,};// Stamp the text stamperpdf.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");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create text stamperPrivate 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 stamperpdf.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")
' Create a semi-transparent watermark behind contentDim watermark As New TextStamper() With { .Text = "CONFIDENTIAL", .FontSize = 60, .FontColorCode = "#CCCCCC", .Opacity = 25, .Rotation = -45, .IsStampBehindContent = True, .VerticalAlignment = VerticalAlignment.Middle, .HorizontalAlignment = HorizontalAlignment.Center}
' Create a semi-transparent watermark behind content
Dim watermark As New TextStamper() With {
.Text = "CONFIDENTIAL",
.FontSize = 60,
.FontColorCode = "#CCCCCC",
.Opacity = 25,
.Rotation = -45,
.IsStampBehindContent = True,
.VerticalAlignment = VerticalAlignment.Middle,
.HorizontalAlignment = HorizontalAlignment.Center
}
摘要
IronPDF 的盖章功能可在现有 PDF 文档中添加文本、图像、HTML 内容和条形码。 四种具有广泛自定义选项的专业标注类可创建带有水印、页眉、页脚和注释的专业文档。 带有各种测量单位和对齐选项的定位系统可确保像素完美定位。 使用简单的文本图章或带有 CSS 风格的复杂 HTML 布局。 IronPDF 的戳记 API 为企业级 PDF 操作提供了灵活性和控制性。
How can I create a semi-transparent watermark with IronPDF?
You can create a semi-transparent watermark using the `Opacity` property in the stamper classes of IronPDF. For example, set `Opacity` to 25 to apply a lightly transparent watermark on the PDF document.
What barcode types can I stamp on PDFs using IronPDF?
IronPDF's `BarcodeStamper` class supports QRCode, Code128, and Code39 barcode types. Each type is suitable for different encoding requirements and can be customized for size and positioning.
Is it possible to add hyperlinks to stamped elements in IronPDF?
Yes, IronPDF allows you to add hyperlinks to stamped elements through the `Hyperlink` property. However, note that HTML links (a tags) aren't preserved by stamping.
Can I use Google Fonts when stamping text on a PDF document?
Yes, IronPDF allows you to use Google Fonts with the `TextStamper`. Set the `UseGoogleFont` property to true and specify the desired font family to use Google Fonts in your text stamps.