Adding repeated watermarks

Rrepeated watermark

Enhance the visual appeal and branding of your documents with the power of repeated or tiled watermarks. This innovative feature allows you to seamlessly integrate patterns of text or images across your pages, creating a professional and cohesive look. Whether you’re aiming for subtle branding, artistic expression, or document security, the ability to configure the spacing, rotation, and style of these watermarks provides unparalleled customization. Explore the possibilities and make your documents stand out with the elegance of tiled watermarks.

Text repeated watermark

The provided code snippet demonstrates how to add a tiled watermark to a document. To configure tiling settings, we can utilize the dedicated class TileOptions. In this example, we set the LineSpacing property, determining the spacing between parallel tiles, to 12 percent of the page size. Additionally, we define the WatermarkSpacing property, which sets the spacing between watermarks in the line, to be 10 percent of the page size. Next image helps to understand the purpose of LineSpacing and WatermarkSpacing settings: adding-repeated-watermarks

Furthermore, we apply a watermark rotation of 30 degrees for added customization.

    using (Watermarker watermarker = new Watermarker("sample.pdf"))
    {
        // Initialize the font to be used for watermark
        Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic);

        // Create the watermark object
        var watermark = new TextWatermark("Watermark", font);
        watermark.ForegroundColor = Color.Red;

        // Configure tile options
        watermark.TileOptions = new TileOptions()
        {
            LineSpacing = new MeasureValue()
            {
                MeasureType = TileMeasureType.Percent,
                Value = 12
            },
            WatermarkSpacing = new MeasureValue()
            {
                MeasureType = TileMeasureType.Percent,
                Value = 10
            },
        };

        // Set watermark properties
        watermark.Opacity = 0.2;
        watermark.RotateAngle = -30;

        // Add watermark
        watermarker.Add(watermark);
        watermarker.Save("result.pdf");
    }        

The output of the above mentioned code is represented below, showcasing repeated text watermarks: text repeated watermarks

The common rotation of watermarks on the above image is done relative to the left edge of the document. It’s also possible to do the common rotation relative to the bottom left edge of the document. For this need to set property RotateAroundOrigin of the class TileOptions in the true.

watermark.TileOptions.RotateAroundOrigin = true;

In such case the result of repeated watermark looks like this: repeated watermarks rotaion around the center

Class TileOptions includes a TileType property, providing the ability to configure the tile template. The default value is Straight mode, but we can change it. For instance, in the previous example, if we add the setting

   watermark.TileOptions.TileType = TileType.Offset

it enables the offset style. In the context of watermarks and tiling, the “offset style” refers to a specific arrangement where each tile is positioned with a shift or offset from the previous one. Instead of aligning tiles in a straightforward, parallel manner, the offset style introduces a displacement, creating a more dynamic and visually interesting pattern. This shift can occur horizontally, vertically, or both, depending on the specific settings applied. In this case, the output will exhibit the following effect: adding-repeated-watermarks

The TileType enum supports a range of tile templates, including OneThirdOffset and BasketWeave, to accommodate diverse design needs. Setting

   watermark.TileOptions.TileType = TileType.BasketWeave

It produces the following visual result for the BasketWeave tile watermark pattern in the document: adding-repeated-watermarks

Image repeated watermark

The repeated watermark feature also supports image watermarks. The following C# code demonstrates how to add repeated image watermarks to a PDF document with rotation.

    using (Watermarker watermarker = new Watermarker("sample.pdf"))
    {
        // Initialize the font to be used for watermark
        Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic);

        // Create the image watermark object
        var watermark = new ImageWatermark(imagePath);

        // Configure tile options
        watermark.TileOptions = new TileOptions()
        {
            LineSpacing = new MeasureValue()
            {
                MeasureType = TileMeasureType.Percent,
                Value = 12
            },
            WatermarkSpacing = new MeasureValue()
            {
                MeasureType = TileMeasureType.Percent,
                Value = 10
            },
        };

        // Set watermark properties
        watermark.Opacity = 0.3;
        watermark.RotateAngle = -30;

        // Add watermark
        watermarker.Add(watermark);
        watermarker.Save("result.pdf");
    }        

This is the resulting appearance of the document after applying tiled image watermarks: adding-repeated-watermarks