Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 17, 2021 05:16
Show Gist options
  • Save aspose-com-gists/9126e502f254c5aa98b378b14215b804 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9126e502f254c5aa98b378b14215b804 to your computer and use it in GitHub Desktop.
Apply Theme in PowerPoint Presentations using Java
// Load or create presentation
Presentation pres = new Presentation("pres.pptx");
try {
// Get available styles
int numberOfBackgroundFills = pres.getMasterTheme().getFormatScheme().getBackgroundFillStyles().size();
System.out.println("Number of background fill styles for theme is " + numberOfBackgroundFills);
// Set style
pres.getMasters().get_Item(0).getBackground().setStyleIndex(2);
// Save presentation
pres.save("out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// Load or create presentation
Presentation pres = new Presentation();
try {
// Add a shape
IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
// Set fill type
shape.getFillFormat().setFillType(FillType.Solid);
// Set scheme color
shape.getFillFormat().getSolidFillColor().setSchemeColor(SchemeColor.Accent4);
// Save presentation
pres.save("out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// Load or create presentation
Presentation pres = new Presentation();
try {
// Add shape
IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
// Add paragraph and set text
Paragraph paragraph = new Paragraph();
Portion portion = new Portion("Theme text format");
paragraph.getPortions().add(portion);
shape.getTextFrame().getParagraphs().add(paragraph);
// Set font
portion.getPortionFormat().setLatinFont(new FontData("+mn-lt"));
// Save presentation
pres.save("out.pptx", SaveFormat.Pptx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment