DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\diagram.vsdx"using(Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions)){// Initialize text watermarkTextWatermarktextWatermark=newTextWatermark("Test watermark 1",newFont("Calibri",19));DiagramShapeWatermarkOptionstextWatermarkOptions=newDiagramShapeWatermarkOptions();textWatermarkOptions.PlacementType=DiagramWatermarkPlacementType.BackgroundPages;// Add text watermark to all background pageswatermarker.Add(textWatermark,textWatermarkOptions);// Initialize image watermarkusing(ImageWatermarkimageWatermark=newImageWatermark("logo.jpg")){DiagramShapeWatermarkOptionsimageWatermarkOptions=newDiagramShapeWatermarkOptions();imageWatermarkOptions.PlacementType=DiagramWatermarkPlacementType.ForegroundPages;// Add image watermark to all foreground pageswatermarker.Add(imageWatermark,imageWatermarkOptions);}watermarker.Save("diagram.vsdx");}
Adding watermark on separate background page
In some cases, you may want to place the watermark on separate newly created background pages. In this case, use below code.
DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\diagram.vsdx"using(Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions)){// Initialize watermark of any supported typeTextWatermarktextWatermark=newTextWatermark("Test watermark 1",newFont("Calibri",19));DiagramShapeWatermarkOptionsoptions=newDiagramShapeWatermarkOptions();options.PlacementType=DiagramWatermarkPlacementType.SeparateBackgrounds;// Create separate background for each page where it is not set. Add watermark to it.watermarker.Add(textWatermark,options);watermarker.Save("diagram.vsdx");}
Add watermark to a particular page
GroupDocs.Watermark allows you to add watermark to a particular page of the document using PageIndex of DiagramPageWatermarkOptions as shown in below example.
DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\diagram.vsdx"using(Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions)){TextWatermarktextWatermark=newTextWatermark("Test watermark",newFont("Calibri",19));DiagramPageWatermarkOptionstextWatermarkOptions=newDiagramPageWatermarkOptions();textWatermarkOptions.PageIndex=0;// Add text watermark to the first pagewatermarker.Add(textWatermark,textWatermarkOptions);using(ImageWatermarkimageWatermark=newImageWatermark("logo.jpg")){DiagramPageWatermarkOptionsimageWatermarkOptions=newDiagramPageWatermarkOptions();imageWatermarkOptions.PageIndex=1;// Add image watermark to the second pagewatermarker.Add(imageWatermark,imageWatermarkOptions);}watermarker.Save("diagram.vsdx");}
Lock watermark
When you’re calling Add method of Watermaker object created for the Diagram document, simple shape is added to the document. There is no difference between added watermark and Visio shapes that are used to create diagrams.
GroupDocs.Watermark allows you to protect watermark from editing in MS Visio by setting IsLocked property of DiagramShapeWatermarkOptions (as shown in the following example).
DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\diagram.vsdx"using(Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions)){TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",19));DiagramShapeWatermarkOptionsoptions=newDiagramShapeWatermarkOptions();options.IsLocked=true;// Editing of the shape in Visio is forbiddenwatermarker.Add(watermark,options);watermarker.Save("diagram.vsdx");}