Using GroupDocs.Watermark, you can add watermark to a particular slide of a PowerPoint presentation in a simplified way. Adding watermark to a particular PowerPoint slide using GroupDocs.Watermark consists of following steps.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);// Add text watermark to the first slide
TextWatermarktextWatermark=newTextWatermark("Test watermark",newFont("Arial",8));PresentationWatermarkSlideOptionstextWatermarkOptions=newPresentationWatermarkSlideOptions();textWatermarkOptions.setSlideIndex(0);watermarker.add(textWatermark,textWatermarkOptions);// Add image watermark to the second slide
ImageWatermarkimageWatermark=newImageWatermark("logo.jpg");PresentationWatermarkSlideOptionsimageWatermarkOptions=newPresentationWatermarkSlideOptions();imageWatermarkOptions.setSlideIndex(1);watermarker.add(imageWatermark,imageWatermarkOptions);watermarker.save("presentation.pptx");watermarker.close();imageWatermark.close();
Protecting watermark using unreadable characters
This feature allows strengthening the protection of text watermark. Using unreadable characters in the watermark text forbids the modification using Find and Replace dialog. The following code sample shows how to include unreadable characters in watermark text using methods setLocked() and setProtectWithUnreadableCharacters() of PresentationWatermarkSlideOptions.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);TextWatermarkwatermark=newTextWatermark("Watermark text",newFont("Arial",19));PresentationWatermarkSlideOptionsoptions=newPresentationWatermarkSlideOptions();options.setLocked(true);options.setProtectWithUnreadableCharacters(true);// Add watermark
watermarker.add(watermark,options);// Save document
watermarker.save("presentation.pptx");watermarker.close();
Getting slide dimensions
If for some reasons you want to use absolute sizing and positioning, you may also need to get the width and height of the slide. Use below code to get the dimensions of a particular slide.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);PresentationContentcontent=watermarker.getContent(PresentationContent.class);System.out.println(content.getSlideWidth());System.out.println(content.getSlideHeight());watermarker.close();
Add watermark to all images inside a particular slide
GroupDocs.Watermark allows you to add watermark to the images inside a particular PowerPoint slide using add() method as shown in below example.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);TextWatermarkwatermark=newTextWatermark("Protected image",newFont("Arial",8));watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermark.setRotateAngle(45);watermark.setSizingType(SizingType.ScaleToParentDimensions);watermark.setScaleFactor(1);// Get all images from the first slide
PresentationContentcontent=watermarker.getContent(PresentationContent.class);WatermarkableImageCollectionimages=content.getSlides().get_Item(0).findImages();// Add watermark to all found images
for(WatermarkableImageimage:images){image.add(watermark);}watermarker.save("presentation.pptx");watermarker.close();
Working with masters, layouts, and notes
GroupDocs.Watermark enables you to access all types of the service slides in a PowerPoint presentation. Following methods of PresentationContent allows access to the coresponding slide types using the API
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",8));PresentationContentcontent=watermarker.getContent(PresentationContent.class);// Add watermark to all master slides
PresentationWatermarkMasterSlideOptionsmasterSlideOptions=newPresentationWatermarkMasterSlideOptions();masterSlideOptions.setMasterSlideIndex(-1);watermarker.add(watermark,masterSlideOptions);// Add watermark to all layout slides
if(content.getLayoutSlides()!=null){PresentationWatermarkLayoutSlideOptionslayoutSlideOptions=newPresentationWatermarkLayoutSlideOptions();layoutSlideOptions.setLayoutSlideIndex(-1);watermarker.add(watermark,masterSlideOptions);}// Add watermark to all notes slides
for(inti=0;i<content.getSlides().getCount();i++){if(content.getSlides().get_Item(i).getNotesSlide()!=null){PresentationWatermarkNoteSlideOptionsnoteSlideOptions=newPresentationWatermarkNoteSlideOptions();noteSlideOptions.setSlideIndex(i);watermarker.add(watermark,noteSlideOptions);}}// Add watermark to handout master
if(content.getMasterHandoutSlide()!=null){PresentationWatermarkMasterHandoutSlideOptionshandoutSlideOptions=newPresentationWatermarkMasterHandoutSlideOptions();watermarker.add(watermark,handoutSlideOptions);}// Add watermark to notes master
if(content.getMasterNotesSlide()!=null){PresentationWatermarkMasterNotesSlideOptionsmasterNotesSlideOptions=newPresentationWatermarkMasterNotesSlideOptions();watermarker.add(watermark,masterNotesSlideOptions);}watermarker.save("presentation.pptx");watermarker.close();
What is watermark in PowerPoint
When you’re calling add() method of Watermarker class with loaded presentation document, simple shape is added to a PowerPoint document. GroupDocs.Watermark provides some additional options when adding a shape watermark. Use PresentationWatermarkBaseSlideOptions descendant classes to set these options as shown in below example.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",19));watermark.setBackground(true);PresentationWatermarkSlideOptionsoptions=newPresentationWatermarkSlideOptions();// Set the shape name
options.setName("Shape 1");// Set the descriptive (alternative) text that will be associated with the shape
options.setAlternativeText("Test watermark");// Editing of the shape in PowerPoint is forbidden
options.setLocked(true);watermarker.add(watermark,options);watermarker.save("presentation.pptx");watermarker.close();
Applying text effects
You can also apply text effects when adding shape watermark to a PowerPoint slide.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);TextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Segoe UI",19));PresentationTextEffectseffects=newPresentationTextEffects();effects.getLineFormat().setEnabled(true);effects.getLineFormat().setColor(Color.getRed());effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);effects.getLineFormat().setWeight(1);PresentationWatermarkSlideOptionsoptions=newPresentationWatermarkSlideOptions();options.setEffects(effects);watermarker.add(watermark,options);watermarker.save("presentation.pptx");watermarker.close();
Warning
Line format settings are not supported for Ppt presentations at this moment.
Applying image effects
The API also allows you to apply image effects to the shape watermark using below code.
PresentationLoadOptionsloadOptions=newPresentationLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\presentation.pptx"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);ImageWatermarkwatermark=newImageWatermark("logo.png");PresentationImageEffectseffects=newPresentationImageEffects();effects.setBrightness(0.7);effects.setContrast(0.6);effects.setChromaKey(Color.getRed());effects.getBorderLineFormat().setEnabled(true);effects.getBorderLineFormat().setWeight(1);PresentationWatermarkSlideOptionsoptions=newPresentationWatermarkSlideOptions();options.setEffects(effects);watermarker.add(watermark,options);watermarker.save("presentation.pptx");watermarker.close();watermark.close();