Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GroupDocsGists/02f763046a5c3b45f722e88c0ead9029 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/02f763046a5c3b45f722e88c0ead9029 to your computer and use it in GitHub Desktop.
Add Watermark to PDF, Word, PPT, Excel Documents using C#
/*
* Apply Image Watermark to document (PDF, Word, PPT, Excel, ...) using C#
*/
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = "P@$$w0rd";
string filePath = "path/document.docx";
using (Watermarker watermarker = new Watermarker(filePath, loadOptions))
{
// Prepare Watermark Text and appearance.
ImageWatermark watermark = new ImageWatermark("watermark-logo.png")
{
Opacity = 0.7,
X = 70,
Y = 350
};
// Add image watermark to document and save.
watermarker.Add(watermark);
watermarker.Save("path/watermark-document.docx");
}
/*
* Apply Text Watermark to document (PDF, Word, PPT, Excel, ...) using C#
*/
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = "P@$$w0rd";
string filePath = "path/document.pdf";
using (Watermarker watermarker = new Watermarker(filePath, loadOptions))
{
// Prepare Watermark Text and appearance.
TextWatermark watermark = new TextWatermark("Watermark", new Font("Arial", 12))
{
RotateAngle = -45,
Opacity = .3,
ForegroundColor = Color.Red,
};
// Add watermark to document and save.
watermarker.Add(watermark);
watermarker.Save("path/watermark-document.pdf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment