Change Font Styles in PowerPoint Using Java

When creating a PowerPoint document, it’s easy for us to apply different font styles to different parts or paragraphs. And now, this article will demonstrate how to change font styles (font name, font size, font color, bold, italic and underlined) of an existing PowerPoint document by using Free Spire.Presentation for Java.

Import Jar Dependency (2 Methods)
● Download the free API and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.

● You can also add the jar dependency to your maven project by adding the following configurations to the pom.xml.


Relevant code

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;

public class ChangeFontStyles {

public static void main(String[] args) throws Exception {

//Create a Presentation object
Presentation presentation = new Presentation();

//Load the sample PowerPoint file

//Get the text shape
IAutoShape shape = (IAutoShape) presentation.getSlides().get(0).getShapes().get(0);

//Get the first paragraph and change the font color of it
ParagraphEx paragraph = shape.getTextFrame().getParagraphs().get(0);
PortionEx textRange = paragraph.getFirstTextRange();

//Get the second paragraph and make the text bold, italic and unlined
paragraph = shape.getTextFrame().getParagraphs().get(1);
textRange = paragraph.getFirstTextRange();

//Get the third paragraph and change the font name and size
paragraph = shape.getTextFrame().getParagraphs().get(2);
textRange = paragraph.getFirstTextRange();
textRange.getFormat().setLatinFont(new TextFont("Segoe Print"));

//Save the document
presentation.saveToFile("output/ChangeFontStyles.pptx", FileFormat.PPTX_2013);

Sharing Java Code