Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Create PowerPoint Slide Using Java

                         


In this example we are going to create a PowerPoint slide .

HWSL is used to make the Microsoft PowerPoint 97(-2003) file format by pure Java. It supports read and write capabilities of some, but not yet all of the core records.
HSSF provides a way to read PowerPoint presentations, and extracts text from it. It also provides some edit capabilities (currently limited). 

The org.apache.poi.hslf.extractor.PowerPointExtractor class is used to extract text from PowerPoint. It accepts a file or an input stream. The getText() method can be used to get the text from the slides, and the getNotes() method is used to get the text from the notes. The getText(true,true) is used to get the text from both.

To create a slide show we need  org.apache.poi.hslf.usermodel.SlideShow. To accepts a file or an input stream we need a org.apache.poi.hslf.HSLFSlideShow. We use getSlides() and getNotes() to get the slides and notes.

To get blocks of text we need  getTextRuns().
The getTextAsString()  and getTextAsVector() are two methods which are used to get the text back. The getTextAsString() returns a single string with all the text in it and getTextAsVector() returns a 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.

We can add new slides by calling SlideShow.createSlide(), which will add a new slide to the end of the SlideShow. It is not possible to re-order slides, nor to add new text to slides tile now .But currently we can add Escher objects.

The following classes can be  used to create the PowerPoint presentations.

The org.apache.poi.hslf.HSLFSlideShow class handles reading in and writing out files. The org.apache.poi.hslf.record.Record class is used to build a tree of all the records in the file. This allows to access the record. The  org.apache.poi.hslf.record.Record class is base class of all records and also provides the main record generation code, which will build up a tree of records for a file. The org.apache.poi.hslf.usermodel.SlideShow class is builds up model entries from the records, and presents a user facing view of the file. The org.apache.poi.hslf.model.Slide class is used to define a user facing view of a Slide in a SlideShow. The org.apache.poi.hslf.model.Slide class allows us to get at the Text of the slide, and at any drawing objects on it. The org.apache.poi.hslf.model.TextRun class is used to hold all the Text in a given area of the Slide, and will contain one or more RichTextRuns. The org.apache.poi.hslf.usermodel.RichTextRun class is used to hold a run of text, all having the same character and paragraph styling. It is possible to modify text, and/or text styling. The org.apache.poi.hslf.extractor.PowerPointExtractor is used to allow extraction of text from files. The org.apache.poi.hslf.extractor.QuickButCruddyTextExtractor class is used to extract all the text from files very fast, but including deleted text and other bits of Crud.

In this example we are creating a PowerPoint presentation. For this we are creating the object of SlideShow after that we are creating an object of slide and an object of  file output to create a .ppt file .
  
 The code of the program is given below:
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.SlideShow;
import java.io.*;
public class createNewPersentation
  {
    public static void main(String str[])
    {
      try{
    SlideShow slideShow = new SlideShow();
    Slide slide = slideShow.createSlide();
    FileOutputStream out = new FileOutputStream("slideshow.ppt");
    slideShow.write(out);
    out.close();
    }catch(Exception e){}}
  }

The output of the program is given below:

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.