For details, you can visit the full article that explains how to watermark PDF files using C#.
Last active
August 2, 2021 10:40
Add Text and Image Watermarks to PDF files using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Watermark Image to page(s) of PDF file using C# | |
PdfLoadOptions loadOptions = new PdfLoadOptions(); | |
using (Watermarker watermarker = new Watermarker("path/document.pdf", loadOptions)) | |
{ | |
ImageWatermark imageWatermark = new ImageWatermark("watermark-logo.png") | |
{ | |
Opacity = 0.7, | |
X = 70, | |
Y = 350 | |
}; | |
// Adding image watermark to the second page | |
PdfArtifactWatermarkOptions imageWatermarkOptions = new PdfArtifactWatermarkOptions(); | |
imageWatermarkOptions.PageIndex = 1; | |
watermarker.Add(imageWatermark, imageWatermarkOptions); | |
watermarker.Save("path/image-watermark.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Watermark Text to page(s) of PDF file using C# | |
PdfLoadOptions loadOptions = new PdfLoadOptions(); | |
using (Watermarker watermarker = new Watermarker("path/document.pdf", loadOptions)) | |
{ | |
TextWatermark textWatermark = new TextWatermark("Watermark", new Font("Arial", 80)) | |
{ | |
RotateAngle = -45, | |
Opacity = .3, | |
ForegroundColor = Color.DarkBlue, | |
HorizontalAlignment = HorizontalAlignment.Center, | |
VerticalAlignment = VerticalAlignment.Center | |
}; | |
// If you want to add watermark text to any specific page, provde Page Index. | |
/* | |
PdfArtifactWatermarkOptions textWatermarkOptions = new PdfArtifactWatermarkOptions(); | |
textWatermarkOptions.PageIndex = 0; | |
*/ | |
watermarker.Add(textWatermark, textWatermarkOptions); | |
watermarker.Save("path/text-watermark.pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment