The API allows you to extract information about all the slide backgrounds, Removing a particular background and Adding watermark to all background images
Extracting information about all slide backgrounds
The API allows you to extract information about all the slide backgrounds in a PowerPoint document as shown in the following code sample using property BackgroundImage of PresentationSlide.ImageFillFormat.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\presentation.pptx"using(Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions)){PresentationContentcontent=watermarker.GetContent<PresentationContent>();foreach(PresentationSlideslideincontent.Slides){if(slide.ImageFillFormat.BackgroundImage!=null){Console.WriteLine(slide.ImageFillFormat.BackgroundImage.Width);Console.WriteLine(slide.ImageFillFormat.BackgroundImage.Height);Console.WriteLine(slide.ImageFillFormat.BackgroundImage.GetBytes().Length);}}}
Removing a particular background
Following code sample shows how to remove the background image of a particular slide setting the property BackgroundImage to null.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\presentation.pptx"using(Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions)){PresentationContentcontent=watermarker.GetContent<PresentationContent>();content.Slides[0].ImageFillFormat.BackgroundImage=null;watermarker.Save("presentation.pptx");}
Adding watermark to all background images
Using GroupDocs.Watermark, you can also add watermark to the background images that belong to a PowerPoint document as shown in the following code sample.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\presentation.pptx"using(Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions)){// Initialize image or text watermarkTextWatermarkwatermark=newTextWatermark("Protected image",newFont("Arial",8));watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermark.RotateAngle=45;watermark.SizingType=SizingType.ScaleToParentDimensions;watermark.ScaleFactor=1;PresentationContentcontent=watermarker.GetContent<PresentationContent>();foreach(PresentationSlideslideincontent.Slides){if(slide.ImageFillFormat.BackgroundImage!=null){// Add watermark to the imageslide.ImageFillFormat.BackgroundImage.Add(watermark);}}watermarker.Save("presentation.pptx");}
Additional settings for slide background image
GroupDocs.Watermark for .NET also provides the feature that allows you to tile the picture across slide’s background. You can also make the image semi-transparent. Following code sample serves this purpose.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\presentation.pptx"using(Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions)){PresentationContentcontent=watermarker.GetContent<PresentationContent>();PresentationSlideslide=content.Slides[0];slide.ImageFillFormat.BackgroundImage=newPresentationWatermarkableImage(File.ReadAllBytes("background.png"));slide.ImageFillFormat.TileAsTexture=true;slide.ImageFillFormat.Transparency=0.5;watermarker.Save("presentation.pptx");}
Settings background image for charts
GroupDocs.Watermark for .NET also allows you to set the background image for a chart inside PowerPoint document using Charts property. You can use following code sample to achieve this functionality.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\presentation.pptx"using(Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions)){PresentationContentcontent=watermarker.GetContent<PresentationContent>();content.Slides[0].Charts[0].ImageFillFormat.BackgroundImage=newPresentationWatermarkableImage(File.ReadAllBytes("test.png"));content.Slides[0].Charts[0].ImageFillFormat.Transparency=0.5;content.Slides[0].Charts[0].ImageFillFormat.TileAsTexture=true;watermarker.Save("presentation.pptx");}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.