1. Home
  2. Foxit PDF SDK for Windows
  3. How to create Watermarks using Foxit PDF SDK (.NET)

How to create Watermarks using Foxit PDF SDK (.NET)

A watermark is a type of PDF annotation and is widely used in PDF documents. A watermark is a visible embedded overlay on a document consisting of text, a logo, or a copyright notice. The purpose of a watermark is to brand your work and discourage its unauthorized use. Foxit PDF SDK provides APIs to work with watermarks, allowing applications to create, insert, release and remove watermarks.

Example:

How to create a text watermark and insert it into the first page

using foxit.common;
using foxit.pdf;
...
// Assuming PDFDoc doc has been loaded.
WatermarkSettings settings = new WatermarkSettings();
settings.offset_x = 0;
settings.offset_y = 0;
settings.opacity = 90;
settings.position = Position.e_PosTopRight;
settings.rotation = -45.0f;
settings.scale_x = 1.0f;
settings.scale_y = 1.0f;
WatermarkTextProperties text_properties = new WatermarkTextProperties();
text_properties.alignment = Alignment.e_AlignmentCenter;
text_properties.color = 0xF68C21;
text_properties.font_style = WatermarkTextProperties.FontStyle.e_FontStyleNormal;
text_properties.line_space = 1;
text_properties.font_size = 12.0f;
text_properties.font = font;
Watermark watermark = new Watermark(doc, "Foxit PDF SDK\nwww.foxitsoftware.com", text_properties, settings);
watermark.InsertToPage(doc.GetPage(0));
// Save document to file
...

How to create an image watermark and insert it into the first page

using foxit.common;
using foxit.pdf;
...
// Assuming PDFDoc doc has been loaded.
// Assuming PDFPage page has been loaded and parsed.
WatermarkSettings settings = new WatermarkSettings();
settings.flags = (int)(WatermarkSettings.Flags.e_FlagASPageContents | WatermarkSettings.Flags.e_FlagOnTop);
settings.offset_x = 0.0f;
settings.offset_y = 0.0f;
settings.opacity = 20;
settings.position = Position.e_PosCenter;
settings.rotation = 0.0f;
Image image = new Image(image_file);
System.Drawing.Bitmap bitmap = image.GetFrameBitmap(0);
settings.scale_x = page.GetWidth() * 0.618f / bitmap.Width;
settings.scale_y = settings.scale_x;
Watermark watermark = new Watermark(doc, image, 0, settings);
watermark.InsertToPage(doc.GetPage(0));
// Save document to file.
...

How to remove all watermarks from a page

using foxit.common;
using foxit.pdf;
...
// Assuming PDFPage page has been loaded and parsed.
...
page.RemoveAllWatermarks();
...
// Save document to file
...
Updated on October 23, 2019

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial