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);for(PresentationSlideslide:content.getSlides()){if(slide.getImageFillFormat().getBackgroundImage()!=null){System.out.println(slide.getImageFillFormat().getBackgroundImage().getWidth());System.out.println(slide.getImageFillFormat().getBackgroundImage().getHeight());System.out.println(slide.getImageFillFormat().getBackgroundImage().getBytes().length);}}watermarker.close();
Removing a particular background
Following code sample shows how to remove the background image of a particular slide calling the method setBackgroundImage() with null.
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);content.getSlides().get_Item(0).getImageFillFormat().setBackgroundImage(null);watermarker.save("presentation.pptx");watermarker.close();
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"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);// Initialize image or text watermark
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);PresentationContentcontent=watermarker.getContent(PresentationContent.class);for(PresentationSlideslide:content.getSlides()){if(slide.getImageFillFormat().getBackgroundImage()!=null){// Add watermark to the image
slide.getImageFillFormat().getBackgroundImage().add(watermark);}}watermarker.save("presentation.pptx");watermarker.close();
Additional settings for slide background image
GroupDocs.Watermark for Java 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"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);PresentationContentcontent=watermarker.getContent(PresentationContent.class);PresentationSlideslide=content.getSlides().get_Item(0);FileimageFile=newFile("background.png");byte[]imageBytes=newbyte[(int)imageFile.length()];InputStreamimageInputStream=newFileInputStream(imageFile);imageInputStream.read(imageBytes);imageInputStream.close();slide.getImageFillFormat().setBackgroundImage(newPresentationWatermarkableImage(imageBytes));slide.getImageFillFormat().setTileAsTexture(true);slide.getImageFillFormat().setTransparency(0.5);watermarker.save("presentation.pptx");watermarker.close();
Settings background image for charts
GroupDocs.Watermark for Java also allows you to set the background image for a chart inside PowerPoint document using getCharts() method. 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"
Watermarkerwatermarker=newWatermarker("presentation.pptx",loadOptions);PresentationContentcontent=watermarker.getContent(PresentationContent.class);FileimageFile=newFile("test.png");byte[]imageBytes=newbyte[(int)imageFile.length()];InputStreamimageInputStream=newFileInputStream(imageFile);imageInputStream.read(imageBytes);imageInputStream.close();content.getSlides().get_Item(0).getCharts().get_Item(0).getImageFillFormat().setBackgroundImage(newPresentationWatermarkableImage(imageBytes));content.getSlides().get_Item(0).getCharts().get_Item(0).getImageFillFormat().setTransparency(0.5);content.getSlides().get_Item(0).getCharts().get_Item(0).getImageFillFormat().setTileAsTexture(true);watermarker.save("presentation.pptx");watermarker.close();
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.