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:

swift
// Initialize a CPDFWatermark object, specifying the watermark type as an image.
let watermark = CPDFWatermark(document: document, type: .image)

watermark.image = UIImage(named: "Logo")
// Create a Bitmap based on the image file, and set the image source and scaling ratio for the image watermark.

// Configure general properties for the watermark.
watermark.scale = 2.0
watermark.rotation = 45
watermark.opacity = 0.5
watermark.verticalPosition = .center
watermark.horizontalPosition = .center
watermark.tx = 0.0
watermark.ty = 0.0
watermark.isFront = true
watermark.pageString = "0-4"

document.addWatermark(watermark)
// Create a watermark in the document.
document.write(to: self.addImageWatermarkURL)
objective-c
//Initialize a CPDFWatermark object, specifying the watermark type as an image.
CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeImage];
    
watermark.image = [UIImage imageNamed:@"Logo"];
//Create a Bitmap based on the image file, and set the image source and scaling ratio for the image watermark.
//Configure general properties for the watermark.
atermark.scale = 2.0;

watermark.rotation = 45; 
watermark.opacity = 0.5; 
watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; 
watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; 
watermark.tx = 0.0;
watermark.ty = 0.0; 
watermark.isFront = YES; 
watermark.pageString = @"0-4";
[document addWatermark:watermark];
//Create a watermark in the document.
[document writeToURL:self.addImageWatermarkURL];