Learn about how to set background of the PowerPoint presentations using Java: https://blog.aspose.com/2021/08/03/set-slide-background-in-powerpoint-using-java/
Last active
September 3, 2021 06:38
-
-
Save aspose-com-gists/be3886cf5e87682f17010302fb2da064 to your computer and use it in GitHub Desktop.
Set Background of Slides in PowerPoint using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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