Custom Watermarking in Vizit Essential and Instant Previews

With Vizit 6.0 comes the ability to write and register custom watermarks for Vizit Essential and Instant Previews. This article walks you through the process of developing and registering a custom watermark plugin.

Getting Started

If you haven't already, take a look at this article and follow the instructions in it to get started writing your custom code:

The rest of this article will explain the details of how to write the specific code for watermarking.

The Basics

Vizit 6.0 contains a new assembly named Vizit.API.Interfaces. For custom watermarks, you must implement the IWatermarkPlugin interface which contains one method and a property. The basic structure looks like this:

void DrawWatermark(
SizeF size,
Graphics graphics);

string Id { get; }

Implementing the IWatermarkPlugin Interface

When a frame is rendered in Vizit Essential or for an Instant Preview, it is cached. Immediately before the resulting frame is returned to the client, watermarks are drawn. It is done at this stage because the watermark may contain time-sensitive information such as the current time that the frame was viewed. Vizit will call the DrawWatermark method for every watermark that is registered; a registered watermark is one that has been created and deployed through the process described in this KB article. After each registered watermark is executed, Vizit will apply the basic, global watermark which can be configured in Central Administration. If the global watermark field is left blank in Central Administration, it will not be applied, but any custom watermarks that have been registered will be applied.

The following is an example DrawWatermark implementation which draws a logo in the lower-right hand corner of each output frame. This code is written in C# but you can also use if desired.

using System.Drawing;
using System.IO;
using Microsoft.SharePoint;
using WatermarkPlugins.Properties;
using Vizit.API.Interfaces.Plugins;
using System;

namespace WatermarkPlugins
    public class CompanyLogoWatermark : IWatermarkPlugin
        //this allows Vizit to identify your custom plugin
        //make sure this is present and unchanged in your code
        public string Id
            get { return "YourCompany.CompanyLogoWatermark"; }

        //this is the function that defines and draws your custom watermark
        public void DrawWatermark(SizeF size, Graphics graphics)
            // Only draw the company logo on documents viewed in the 
            // root web of the web application.
            if (SPContext.Current.Web.ServerRelativeUrl == "/")
                float width = size.Width * (float).2;
                float height = width * Resources.YourCompany_logo.Height / Resources.YourCompany_logo.Width;

                float x = size.Width - width;
                float y = size.Height - height;

                //draws the watermark
                graphics.DrawImage(Resources.YourCompany_logo, x, y, width, height);

Take note of the conditional check of SPContext. This example shows that you can have watermarks that target specific information about the active context that the frame is being rendered in.

The above code draws an image as a watermark. If you would like to display other information as a watermark, such as text showing the date and time the file was accessed, please reference \CustomAnnotations\Logo.cs in the example plugins ZIP file at the top of this article. Logo.cs contains code which does just that and uses the same graphics engine as watermarks.

Have more questions? Submit a request


Article is closed for comments.
Powered by Zendesk