Skip to content
Guides

Add Image Watermark

The steps to add an image watermark are as follows:

  1. Initialize a CPDFWatermark object, specifying the watermark type as an image.

  2. Create a Bitmap based on the image file, setting the image source and scaling for the image watermark.

  3. Set the general properties for the watermark.

  4. Create the watermark in the document.

This example shows how to add an image watermark:

C#
// Initialize a CPDFWatermark object and specify the watermark type as an image.
CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
Bitmap bitmap = new Bitmap("logo.png");
// Create a Bitmap based on the image file, and set the image source and scaling ratio for the image watermark.
watermark.SetImage(BitmapToByteArray(bitmap), bitmap.Width, bitmap.Height);
watermark.SetScale(2);
// Set general properties for the watermark. 
watermark.SetPages("0-3");
watermark.SetRotation(1);
watermark.SetOpacity(128);
watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
watermark.SetVertOffset(0);
watermark.SetHorizOffset(0);
watermark.SetFront(false);
watermark.SetFullScreen(true);
watermark.SetVerticalSpacing(10);
watermark.SetHorizontalSpacing(10);
// Create a watermark in the document.
watermark.CreateWatermark();