Change Font Styles in PowerPoint Using Java

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
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
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\test.pptx");

//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();
textRange.getFormat().getFill().setFillType(FillFormatType.SOLID);
textRange.getFormat().getFill().getSolidColor().setColor(Color.blue);

//Get the second paragraph and make the text bold, italic and unlined
paragraph = shape.getTextFrame().getParagraphs().get(1);
textRange = paragraph.getFirstTextRange();
textRange.getFormat().isBold(TriState.TRUE);
textRange.getFormat().isItalic(TriState.TRUE);
textRange.getFormat().setTextUnderlineType(TextUnderlineType.DASHED);

//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"));
textRange.getFormat().setFontHeight(22f);

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

--

--

--

Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Service and Maintenance Management — AssetSonar

Cubicle Cultures

How to send an email with Python

Is Your Mobile App Development Company meeting the quality service?

Research on Demand — by Prime Rating

Testing @Parcelize

ERP Tech Talk #1: Optimize Your SQL Query

How to Export a List of AWS EC2 Instances with Tags to Excel?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Data Types in JVM

Java I/O Byte Stream Implementation

First Java Program

Inheritance In Java -10 Program