May 24, 2018, 05:37 AM

News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!


Create PowerPoint Slide Using Java

Started by VelMurugan, Nov 23, 2008, 02:41 AM

previous topic - next topic
Go Down

VelMurugan

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:

Code: [Select]
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){}}
  }

IrudayaRaj

Dear Sir
            Kindly tell me how to read some text from the file and set the text into a slide in java using hslf packages

TommyRiordan

Hi...

I'm new here on this forum with a huge belief that I'll get some knowledge or information about whatever is going on in current IT industry. And I have a question too that how can we make a translator using J2EE .

Makeshk

Hi IrudayaRaj,

>>  Kindly tell me how to read some text from the file and set the text into a slide in java using hslf packages

Use buffered reader to open a file from where you want to collect required texts. Create a file input stream with buffer reader object as parameter. Read the file line by line using readLine() methods.
You can have some validations on the lines read, based on that required text can be written into the slide with write method.

Thanks,
MAK

Makeshk

Hi Tommy,

>> I have a question too that how can we make a translator using J2EE .


Can you be more clear on your query ? Do you mean translator to identify jar, war and ear ?? or you want to make you own translator using J2EE ?

Thanks,
MAK

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens | GinGly :: SMS Backup | Acumen :: Discussion Board | AshokPillar :: Hosting | CineBuzz :: Latest Cinema News | My Kids Diary :: Capture your kids magical moment
Copyright 2005 - 2017 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 10 years - Powered by HostGator Dedicated Server