Add Background to Slides using Apache POI and Aspose.Slides
Contents
[
Hide
]
Aspose.Slides - Add Background to Slides
To use an image as the background of a slide using Aspose.Slides for Java, please follow the steps below:
- Create an instance of Presentation class
- Set the Background Type of the Slide to OwnBackground
- Set the FillType of the Slide Background FillFormat to Picture
- Set the PictureFillMode using the options provided by PictureFillMode enum
- Instantiate IPPImage class with an image that can be used as source picture for the Slide Background using getPictureFillFormat().getPicture().setImage().
- Write the modified presentation file
//Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation();
//Set the background with Image
pres.getSlides().get_Item(0).getBackground().setType (BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Picture);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
//Set the picture
IPPImage imgx = pres.getImages().addImage(new FileInputStream(new File("background.jpg")));
//Add image to presentation's images collection
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
Apache POI SL - HSLF XSLF - Add Background to Slides
Below mentioned example shows how to add background image to slide using Apache POI SL.
SlideMaster master = ppt.getSlidesMasters()[0];
Fill fill = master.getBackground().getFill();
int idx = ppt.addPicture(new File(dataDir + "background.jpg"), Picture.JPEG);
fill.setFillType(Fill.FILL_PICTURE);
fill.setPictureData(idx);
Download Running Code
Download Sample Code
For more details, visit Setting the Image as Background to Slides.