In this tutorial, I’ll introduce how to set title for a slide of PowerPoint document, and then extract the text of the title using Java codes. It’s noted that I used a free third-party library called Free Spire.Presentation for Java to finish the operation above.
Before running codes, we need to add a Jar file to IDEA. You can download the package from the link, unzip it and find Spire.Presentation.jar in the “lib” folder, finally insert it to IDEA. Or you can reference it by using the following Maven configurations.
<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>
Set
Slide Title
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class SetSlideTitle {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Set title for the slide
slide.setTitle("Slide Title");
//Save the resulting document
ppt.saveToFile("output/SetTitle.pptx", FileFormat.PPTX_2013);
}
}
Output
Get
Slide Title
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
public class GetSlideTitle {
public static void main(String[] args) throws Exception {
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a PowerPoint document
ppt.loadFromFile("C:\\Users\\Test1\\Desktop\\SetTitle.pptx");
//Get the first slide
ISlide slide = ppt.getSlides().get(0);
//Print out the title of the slide
String tile = slide.getTitle();
System.out.println(tile);
}
}
Output
No comments:
Post a Comment