POI

POI api Projects

POI api Project 1

Make Colorful Title of PowerPoint Slide
Previous Home Next

In this page of the tutorials we are trying to create a PowerPoint slide and set color full title in the page.

Methods Description

getTextRuns()

In this program this methods get blocks of text. The getTextAsString() and getTextAsVector() are two methods. Both method are used for get the block of the text. The getTextAsString() is used to get the single string with all the text in it and getTextAsVector() is used to get the vector of strings, one for each text record found in the file.

We can change the text via TextRun.setText(String) or RichTextRun.setText(String). But it is not yet possible to add additional TextRuns or RichTextRuns. for performing this task we are using setFontColor(Color color) to change the color of text in this program.

The org.apache.poi.hslf.usermodel.RichTextRun class is used for multiple task like change the textbox style, color, font size, font type etc. Here we are creating the object of RichText and then change the text textbox style, color, font size , font type etc.

Example

package r4r;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;
import java.io.*;
import java.awt.*;
import org.apache.poi.hslf.model.TextBox;
public class makecolorfulltitle {
	public static void main(String a[])
	  {
	  try
	  {  SlideShow Show = new SlideShow();
	  Slide slide1 = Show.createSlide();
	  TextBox ttl = slide1.addTitle();
	  ttl.setText("Rajesh Patel");
	    RichTextRun rtext = ttl.getTextRun().
	getRichTextRuns()[0];
	    rtext.setFontSize(32);
	    rtext.setFontName("Arial");
	    rtext.setBold(true);
	    rtext.setItalic(true);
	    rtext.setUnderlined(true);
	    rtext.setFontColor(Color.BLUE);
	    rtext.setAlignment(TextBox.AlignCenter); 
	  FileOutputStream fos = new FileOutputStream
	("colorfulSlide.ppt");
	  Show.write(fos);
	  fos.close();
	  }catch(Exception e){}
	  }
}
Previous Home Next