DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\diagram.vsdx"
Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions);// Initialize text watermark
TextWatermarktextWatermark=newTextWatermark("Test watermark 1",newFont("Calibri",19));DiagramShapeWatermarkOptionstextWatermarkOptions=newDiagramShapeWatermarkOptions();textWatermarkOptions.setPlacementType(DiagramWatermarkPlacementType.BackgroundPages);// Add text watermark to all background pages
watermarker.add(textWatermark,textWatermarkOptions);// Initialize image watermark
ImageWatermarkimageWatermark=newImageWatermark("logo.jpg");DiagramShapeWatermarkOptionsimageWatermarkOptions=newDiagramShapeWatermarkOptions();imageWatermarkOptions.setPlacementType(DiagramWatermarkPlacementType.ForegroundPages);// Add image watermark to all foreground pages
watermarker.add(imageWatermark,imageWatermarkOptions);watermarker.save("diagram.vsdx");imageWatermark.close();watermarker.close();
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"
Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions);// Initialize watermark of any supported type
TextWatermarktextWatermark=newTextWatermark("Test watermark 1",newFont("Calibri",19));DiagramShapeWatermarkOptionsoptions=newDiagramShapeWatermarkOptions();options.setPlacementType(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");watermarker.close();
DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\diagram.vsdx"
Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions);TextWatermarktextWatermark=newTextWatermark("Test watermark",newFont("Calibri",19));DiagramPageWatermarkOptionstextWatermarkOptions=newDiagramPageWatermarkOptions();textWatermarkOptions.setPageIndex(0);// Add text watermark to the first page
watermarker.add(textWatermark,textWatermarkOptions);ImageWatermarkimageWatermark=newImageWatermark("logo.jpg");DiagramPageWatermarkOptionsimageWatermarkOptions=newDiagramPageWatermarkOptions();imageWatermarkOptions.setPageIndex(1);// Add image watermark to the second page
watermarker.add(imageWatermark,imageWatermarkOptions);watermarker.save("diagram.vsdx");watermarker.close();imageWatermark.close();
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 calling setLocked() method of DiagramShapeWatermarkOptions (as shown in the following example).
DiagramLoadOptionsloadOptions=newDiagramLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\diagram.vsdx"
Watermarkerwatermarker=newWatermarker("diagram.vsdx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",19));DiagramShapeWatermarkOptionsoptions=newDiagramShapeWatermarkOptions();options.setLocked(true);// Editing of the shape in Visio is forbidden
watermarker.add(watermark,options);watermarker.save("diagram.vsdx");watermarker.close();