Customize watermarks

GroupDocs.Watermark lets you control how a watermark looks and where it appears. Adjust color, font, alignment, rotation, opacity, and scaling to match your document’s style.

Customize text watermarks

Use TextWatermark properties such as foreground_color, opacity, rotate_angle, sizing_type, scale_factor, horizontal_alignment, vertical_alignment, x, y, width, height, and consider_parent_margins. The example below scales a “DRAFT” watermark to the page, rotates it 45°, and makes it half-transparent.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font, Color, SizingType
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment

def customize_watermark():
    with Watermarker("./sample.pdf") as watermarker:
        watermark = TextWatermark("DRAFT", Font("Arial", 42.0))
        watermark.foreground_color = Color.dark_orange
        # Scale the watermark relative to the page and rotate it
        watermark.sizing_type = SizingType.SCALE_TO_PARENT_DIMENSIONS
        watermark.scale_factor = 0.7
        watermark.rotate_angle = 45.0
        watermark.opacity = 0.5
        watermark.horizontal_alignment = HorizontalAlignment.CENTER
        watermark.vertical_alignment = VerticalAlignment.CENTER

        watermarker.add(watermark)
        watermarker.save("./output.pdf")

if __name__ == "__main__":
    customize_watermark()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 351 KB)

Download full output

Use case: Apply branded or legal disclaimers in a consistent style across pages (for example, “Confidential – Do Not Distribute”).

Customize image watermarks

Image watermarks support the same positioning, rotation, and opacity properties. Place a logo, stamp, or seal exactly where you need it:

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import ImageWatermark
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment

def customize_image_watermark():
    with Watermarker("./sample.pdf") as watermarker:
        with ImageWatermark("./stamp.png") as watermark:
            watermark.horizontal_alignment = HorizontalAlignment.RIGHT
            watermark.vertical_alignment = VerticalAlignment.TOP
            watermark.rotate_angle = 15.0
            watermark.opacity = 0.8
            watermarker.add(watermark)
        watermarker.save("./output.pdf")

if __name__ == "__main__":
    customize_image_watermark()

sample.pdf and stamp.png are the sample files used in this example. Download sample.pdf and stamp.png.

Binary file (PDF, 307 KB)

Download full output