In this simple and elaborative tutorial, we will exhibit, how to add image watermark in PPTX Presentation using C# without PowerPoint installed. Now a days, PPTX is a popular format for PowerPoint presentations but you may use this example for PPT format as well for adding image watermark to protect intellectual property rights of your presentation.
Steps to add image watermark to PPTX presentation in C#
- Download Aspose.Slides for .NET package from NuGet.org
- Use Aspose.Slides namespace to load and add watermark
- Set license using SetLicense method
- Load the presentation to add picture watermark using Presentation Class object
- Load the watermark/logo image in presentation image collection
- Access and iterate through Master Slide/s inside presentation
- For each master slide, add a PictureFrame with added watermark image
- Format the shape properties
- Apply locking on the added shape to protect image watermark
- Save watermarked presentation
Earlier, we looked into How to Insert Draft Watermark in PowerPoint Presentation in C# in another how-to topic. But this topic describes the steps to add image watermark in PowerPoint presentation in C#. You are no more dependent on Microsoft PowerPoint or Interop for using this feature and can execute the code seamlessly on all platforms.
Above all, the unique shape locking feature that is offered by Aspose.Slides is not even available in PowerPoint publicly to protect your watermark image. You can protect the intellectual property rights of the presentation by using locks feature and applying it to image watermark shape to disallow any modification or tempering in PowerPoint presentation.
Code to Add Image Watermark in PowerPoint in C# without Interop
using System; | |
using System.Drawing; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace SlidesWatermark | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string PathForWatermarkPptFile = @"Y:\Downloads\"; | |
License license = new License(); | |
license.SetLicense(PathForWatermarkImageFile + "Conholdate.Total.Product.Family.lic"); | |
//Load the presentation to insert watermark | |
Presentation WatermarkPptxPresentation = new Presentation(PathForWatermarkPptFile + "PictureWatermark.pptx"); | |
// Loading watermark image to add in PPTX | |
System.Drawing.Image WatermarkLogo = (System.Drawing.Image)new Bitmap("Picture Watermark Logo.jpg"); | |
IPPImage WatermarkImage = WatermarkPptxPresentation.Images.AddImage(WatermarkLogo); | |
//Accessing the master slides for adding watermark image | |
foreach (IMasterSlide masterSlide in WatermarkPptxPresentation.Masters) | |
{ | |
//Adding a Ppt watermark shape for logo image | |
IPictureFrame PptxWatermark = masterSlide.Shapes.AddPictureFrame(ShapeType.Rectangle,0, 0, | |
200, 50, WatermarkImage); | |
//Set the rotation angle of the shape | |
PptxWatermark.Rotation = 325; | |
//Lock Pptx watermark image shape for protection in PowerPoint | |
PptxWatermark.ShapeLock.SizeLocked = true; | |
PptxWatermark.ShapeLock.SelectLocked = true; | |
PptxWatermark.ShapeLock.PositionLocked = true; | |
} | |
//Saving the image watermark PPTX presentation file | |
WatermarkPptxPresentation.Save(PathForWatermarkPptFile + "ImageWatermarkedPresentation.pptx", | |
SaveFormat.Pptx); | |
} | |
} | |
} |
The example is suitable in any .NET application environment using the C# including ASP.NET web application, Windows Forms application and Console based applications. It can be used on your local work machine or on any server having .NET Framework installed.