Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 3, 2021 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/be3886cf5e87682f17010302fb2da064 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/be3886cf5e87682f17010302fb2da064 to your computer and use it in GitHub Desktop.
Set Background of Slides in PowerPoint using Java
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation("presentation.pptx");
try {
// Set the background color of the Master ISlide to green
pres.getMasters().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getMasters().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid);
pres.getMasters().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
// Save presentation
pres.save("MasterBG.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation("presentation.pptx");
try {
// Set the background color of the first ISlide to blue
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
// Save the presentation
pres.save("ContentBG.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation("presentation.pptx");
try {
// Apply Gradient effect to the Background
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Gradient);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getGradientFormat().setTileFlip(TileFlip.FlipBoth);
// Save presentation
pres.save("ContentBG_Grad.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation();
try {
// 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(Files.readAllBytes(Paths.get("Desert.jpg")));
// Add image to presentation's images collection
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
// Save presentation
pres.save("ContentBG_Img.pptx", SaveFormat.Pptx);
} catch (IOException e) {
} finally {
if (pres != null) pres.dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment