Created
August 17, 2022 11:49
-
-
Save conholdate-docs-gists/07fa3962d7184541a3a822a1e1273eba to your computer and use it in GitHub Desktop.
Different way to add watermarks in PDF | https://docs.conholdate.com/net/watermarks-in-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
PdfLoadOptions loadOptions = new PdfLoadOptions(); | |
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf, loadOptions)) | |
{ | |
PdfAnnotationWatermarkOptions options = new PdfAnnotationWatermarkOptions(); | |
// Add text watermark | |
TextWatermark textWatermark = new TextWatermark("This is a annotation watermark", new Font("Arial", 8)); | |
textWatermark.HorizontalAlignment = HorizontalAlignment.Left; | |
textWatermark.VerticalAlignment = VerticalAlignment.Top; | |
watermarker.Add(textWatermark, options); | |
// Add image watermark | |
using (ImageWatermark imageWatermark = new ImageWatermark(Constants.ProtectJpg)) | |
{ | |
imageWatermark.HorizontalAlignment = HorizontalAlignment.Right; | |
imageWatermark.VerticalAlignment = VerticalAlignment.Top; | |
watermarker.Add(imageWatermark, options); | |
} | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
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
PdfLoadOptions loadOptions = new PdfLoadOptions(); | |
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf, loadOptions)) | |
{ | |
PdfArtifactWatermarkOptions options = new PdfArtifactWatermarkOptions(); | |
// Add text watermark | |
TextWatermark textWatermark = new TextWatermark("This is an artifact watermark", new Font("Arial", 8)); | |
textWatermark.HorizontalAlignment = HorizontalAlignment.Right; | |
watermarker.Add(textWatermark, options); | |
// Add image watermark | |
using (ImageWatermark imageWatermark = new ImageWatermark(Constants.LogoBmp)) | |
{ | |
watermarker.Add(imageWatermark, options); | |
} | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
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
PdfLoadOptions loadOptions = new PdfLoadOptions(); | |
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf, loadOptions)) | |
{ | |
TextWatermark textWatermark = new TextWatermark("This is a print only test watermark. It won't appear in view mode.", new Font("Arial", 8)); | |
bool isPrintOnly = true; | |
// Annotation will be printed, but not displayed in pdf viewing application | |
PdfAnnotationWatermarkOptions options = new PdfAnnotationWatermarkOptions(); | |
options.PageIndex = 0; | |
options.PrintOnly = isPrintOnly; | |
watermarker.Add(textWatermark, options); | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the complete article: https://docs.conholdate.com/net/watermarks-in-pdf/