Apache Poi PPT Tutorial
Apache Poi PPT Tutorial
Apache Poi PPT Tutorial
Audience
This tutorial is designed for all the readers working on Java and especially
those who want to create, read, write, and modify PPT files using Java.
Prerequisites
A general awareness of Java programing with JDK1.5 or later versions and IO
concepts in Java are the only prerequisites to understand this tutorial.
All the content and graphics published in this e-book are the property of Tutorials Point
(I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or
republish any contents or a part of contents of this e-book in any manner without written
consent of the publisher.
The API of Apache POI contains a number of methods and classes. In this tutorial, we
have used only some of those for demonstration purpose. We encourage the readers to
refer the complete API document for a comprehensive understanding.
We strive to update the contents of our website and tutorials as timely and as precisely
as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I)
Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of
our website or its contents including this tutorial. If you discover any errors on our
website or in this tutorial, please notify us at [email protected]
i
Table of Contents
About the Tutorial .............................................................................................................................i
Audience ...........................................................................................................................................i
Prerequisites .....................................................................................................................................i
Presentation .....................................................................................................................................9
Slide ...............................................................................................................................................10
HyperLink .......................................................................................................................................15
ii
5. PRESENTATION .................................................................................................................. 16
8. IMAGES ............................................................................................................................. 46
iii
Apache POI – PPT
Any Java programmer who wants to produce MS Office files as output must use
a predefined and read-only API to do so.
XSSF (XML SpreadSheet Format): It is used for .xlsx file format of MS-
Excel.
XWPF (XML Word Processor Format): It is used to read and write .docx
extension files of MS-Word.
HSLF (Horrible Slide Layout Format): It is used to read, create, and edit
PowerPoint presentations.
This tutorial guides you through the process of working on Microsoft PowerPoint
presentation using Java. Therefore the discussion is confined to XSLF
component.
2
Apache POI – PPT
This chapter takes you through some of the flavors of Java PowerPoint API and
their features. There are many vendors who provide Java PPT related APIs;
some of them are considered in this chapter.
Apache POI
Apache POI is a 100% open source library provided by Apache Software
Foundation. Most of the small and medium scale application developers depend
heavily on Apache POI (HSLF + XSLF). It supports all the basic features of PPT
libraries; however, rendering and text extraction are its main features. Given
below is the architecture of Apache POI for PPT.
3
Apache POI – PPT
4
Apache POI – PPT
This chapter takes you through the process of setting up Apache POI on
Windows and Linux based systems. Apache POI can easily be installed and
integrated with your current Java environment, following a few simple steps
without any complex setup procedures. User administration is required for
installation.
System Requirements
JDK Java SE 2 JDK 1.5 or above
If the Java installation has been done properly, then it will display the current
version and specification of your Java installation. A sample output is given in
the following table.
5
Apache POI – PPT
● We assume that the readers of this tutorial have Java SDK version 1.7.0_60
installed on their system.
● In case you do not have Java SDK, download its current version from
http://www.oracle.com/technetwork/java/javase/downloads/index.html and
install it.
Platform Description
Append the full path of Java compiler location to the System Path.
Platform Description
Execute the command java -version from the command prompt as explained
above.
6
Apache POI – PPT
where the required libraries can be linked to your Java program. Let us assume
the files are collected in a folder on C drive.
The following images show the directories and the file structures inside the
downloaded folder:
Add the complete path of the five jars as highlighted in the above image to the
CLASSPATH.
Platform Description
“C:\poi-3.9\poi-3.9-20121203.jar;”
Windows “C:\poi-3.9\poi-ooxml-3.9-20121203.jar;”
“C:\poi-3.9\poi-ooxml-schemas-3.9-20121203.jar;”
“C:\poi-3.9\ooxml-lib\dom4j-1.6.1.jar;”
“C:\poi-3.9\ooxml-lib\xmlbeans-2.3.0.jar;.;”
7
Apache POI – PPT
Export CLASSPATH=$CLASSPATH:
/usr/share/poi-3.9/poi-3.9-20121203.tar:
/usr/share/poi-3.9/poi-ooxml-schemas-3.9-20121203.tar:
Linux
/usr/share/poi-3.9/poi-ooxml-3.9-20121203.tar:
/usr/share/poi-3.9/ooxml-lib/dom4j-1.6.1.tar:
/usr/share/poi-3.9/ooxml-lib/xmlbeans-2.3.0.tar
8
Apache POI – PPT
In this chapter, we will learn about a few classes and methods under Apache POI
API that are crucial to work on PPT files using Java programs.
Presentation
To create and manage a presentation, you have a class called XMLSlideShow in
the package org.apache.poi.xslf.usermodel. Given below are some important
methods and a constructor of this class.
Class: XMLSlideShow
Package: org.apache.poi.xslf.usermodel
1 XMLSlideShow(java.io.InputStream inputStream)
2 XSLFSlide createSlide()
4 java.util.List<XSLFPictureData> getAllPictures()
5 java.awt.Dimension getPageSize()
9
Apache POI – PPT
Using this method, you can get to know the current page size.
6 XSLFSlideMaster[] getSlideMasters()
7 XSLFSlide[] getSlides()
Slide
To create and manage a slide in a presentation, the methods of the XSLFSlide
class are used. Some important methods of this class are mentioned below.
Class: XSLFSlide
Package: org.apache.poi.xslf.usermodel
1 XSLFBackground getBackground()
2 XSLFSlideLayout getSlideLayout()
3 XSLFSlideMaster getSlideMaster()
10
Apache POI – PPT
4 XSLFTheme getTheme()
5 java.lang.String getTitle()
Slide Master
It is the component of the presentation having different slide layouts. The
XSLFSlideMaster class gives you access to it. Mentioned below are some
important methods of this class.
Class: XSLFSlideMaster
Package: org.apache.poi.xslf.usermodel
1 XSLFBackground getBackground()
3 XSLFSlideLayout[] getSlideLayouts()
Slide Layout
The POI library has a class called XSLFSlideLayout, using which you can
manage the layouts of a slide.
11
Apache POI – PPT
Class: XSLFSlideLayout
Package: org.apache.poi.xslf.usermodel
This method will copy the placeholders from this layout to the given
slide.
Text Paragraph
You can write content to the slide using XSLFTextParagraph class. Below
mentioned are some important methods of this class.
Class: XSLFTextParagraph
Package: org.apache.poi.xslf.usermodel
1 XSLFTextRun addLineBreak()
2 XSLFTextRun addNewTextRun()
12
Apache POI – PPT
Text Run
This is the lowest level of text separation within a text body. You have
XSLFTextRun class to manage the text run of a paragraph. Below mentioned
are some important methods of this class.
Class: XSLFTextParagraph
Package: org.apache.poi.xslf.usermodel
1 XSLFHyperlink createHyperlink()
2 XSLFHyperlink getHyperlink()
3 java.lang.String getText()
13
Apache POI – PPT
Text shape
In PPT, we have shapes that can hold text within them. We can manage these
using XSLFTextShape class. Mentioned below are some important methods of
this class.
Class: XSLFTextShape
Package: org.apache.poi.xslf.usermodel
2 Placeholder getTextType()
14
Apache POI – PPT
3 void clearText()
4 XSLFTextParagraph addNewTextParagraph()
HyperLink
The POI library has a class called XSLFHyperlink using which you can create a
hyperlink in the presentation. Mentioned below are some important methods of
this class.
Class: XSLFHyperlink
Package: org.apache.poi.xslf.usermodel
1 java.net.URI getTargetURL()
15
Apache POI – PPT
5. PRESENTATION
ppt.write(out);
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
16
Apache POI – PPT
ppt.write(out);
out.close();
Save the above Java code as CreatePresentation.java, and then compile and
execute it from the command prompt as follows:
$javac CreatePresentation.java
$java CreatePresentation
If your system environment is configured with the POI library, it will compile and
execute to generate a blank PPT file named example1.pptx in your current
directory and display the following output on the command prompt:
17
Apache POI – PPT
You can add slides to a presentation using the createSlide() method of the
XMLSlideShow class which is in the org.poi.xslf.usermodel package.
18
Apache POI – PPT
Given below is the complete program to open and add slides to an existing PPT:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
//adding slides to it
19
Apache POI – PPT
ppt.write(out);
out.close();
Save the above Java code as EditPresentation.java, and then compile and
execute it from the command prompt as follows:
$javac EditPresentation.java
$java EditPresentation
20
Apache POI – PPT
The output PPT document with newly added slides looks as follows:
After adding slides to a PPT, you can add, perform, read, and write operations
on the slides.
21
Apache POI – PPT
6. SLIDE LAYOUTS
In the previous chapter, you have seen how to create empty slides and how to
add slides to it. In this chapter, you will learn how to get the list of available
slides, and how to create a slide with different layouts.
There are different slide masters and in each slide master, there are
several slide layouts.
You can get the list of the slide masters using the getSlideMasters()
method of the XMLSlideShow class.
You can get the list of the slide layouts from each slide master using the
getSlideLayouts() method of the XSLFSlideMaster class.
You can get the name of the slide layout from the layout object using the
getType() method of the XSLFSlideLayout class.
Given below is the complete program to get the list of available slide layouts in
the PPT:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
22
Apache POI – PPT
System.out.println(layout.getType());
Save the above Java code as SlideLayouts.java, and then compile and execute
it from the command prompt as follows:
$javac SlideLayouts.java
23
Apache POI – PPT
$java SlideLayouts
TITLE
PIC_TX
VERT_TX
TWO_TX_TWO_OBJ
BLANK
VERT_TITLE_AND_TX
TITLE_AND_CONTENT
TITLE_ONLY
SECTION_HEADER
TWO_OBJ
OBJ_TX
Shown below are some of the sample slide layouts available with MS-Office 360,
2013 edition.
24
Apache POI – PPT
Title Layout
Let us create a slide in a PPT using Title layout. Follow the steps given below:
Step 2: Get the list of slide masters using the getSlideMasters() method.
Thereafter, select the desired slide master using the index as shown below:
Here we are getting the default slide master which is in the 0th location of the
slide masters array.
Step 3: Get the desired layout using the getLayout() method of the
XSLFSlideMaster class. This method accepts a parameter where you have to
25
Apache POI – PPT
pass one of the static variable of the SlideLayoutclass, which represents our
desired layout. There are several variables in this class where each variable
represents a slide layout.
The code snippet given below shows how to create a title layout:
title1.setText("Tutorials point");
Given below is the complete program to create a slide with Title layout in a
presentation:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
26
Apache POI – PPT
// creating presentation
XSLFSlideLayout titleLayout =
slideMaster.getLayout(SlideLayout.TITLE);
title1.setText("Tutorials point");
27
Apache POI – PPT
ppt.write(out);
out.close();
Save the above Java code as TitleLayout.java, and then compile and execute it
from the command prompt as follows:
$javac TitleLayout.java
$java TitleLayout
The PPT document with newly added Title layout slide appears as follows:
28
Apache POI – PPT
Step 2: Get the list of slide masters using the getSlideMasters() method.
Select the desired slide master using the index as shown below:
Here we are getting the default slide master which is in the 0th location of the
slide masters array.
Step 3: Get the desired layout using the getLayout() method of the
XSLFSlideMaster class. This method accepts a parameter where you have to
pass one of the static variable of the SlideLayout class which represents our
desired layout. There are several variables in this class that represent slide
layouts.
The following code snippet shows how to create title and content layout:
XSLFSlideLayout contentlayout =
slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
Step 4: Create a new slide by passing the slide layout object as parameter.
title1.setText("Introduction");
29
Apache POI – PPT
Step 6: Clear the existing text in the slide using the clearText() method of the
XSLFTextShape class.
body.clearText();
body.addNewTextParagraph().addNewTextRun().setText("this is my first
slide body");
Given below is the complete program to create a slide with Title layout in a
presentation:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
30
Apache POI – PPT
//creating presentation
XSLFSlideLayout slidelayout =
slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
title.setText("introduction");
body.clearText();
31
Apache POI – PPT
body.addNewTextParagraph().addNewTextRun().setText("this is my
ppt.write(out);
out.close();
Save the above Java code as TitleLayout.java, and then compile and execute it
from the command prompt as follows:
$javac TitleLayout.java
$java TitleLayout
32
Apache POI – PPT
The PPT document with newly added Title layout slide appears as follows:
In the same way, you can create slides with different layouts as well.
33
Apache POI – PPT
7. MANAGEMENT OF SLIDES
After completing this chapter, you will be able to delete, reorder, and perform
read and write operations on a slide.
Changing a Slide
We can change the page size of a slide using the setPageSize() method of the
XMLSlideShow class.
//create presentation
Get the size of the current slide using the getPageSize() method of the
XMLSlideShow class.
The complete program for changing the size of a slide is given below:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
34
Apache POI – PPT
TitleAndContentLayout.pptx");
//create presentation
System.out.println("width :"+pgw);
System.out.println("height :"+pgh);
ppt.setPageSize(new java.awt.Dimension(2048,1536));
ppt.write(out);
out.close();
Save the above Java code as ChangingSlide.java, and then compile and
execute it from the command prompt as follows:
$javac ChangingSlide.java
$java ChangingSlide
width :720
height :540
36
Apache POI – PPT
Given below is the snapshot of the presentation before changing the slide size:
Reordering Slides
You can set the slide order using the setSlideOrder() method. Given below is
the procedure to set the order of the slides.
37
Apache POI – PPT
Select a slide from the array of the slides, and change the order using the
setSlideOrder() method as shown below:
ppt.setSlideOrder(selectesdslide, 1);
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
38
Apache POI – PPT
ppt.setSlideOrder(selectesdslide, 0);
ppt.write(out);
out.close();
Save the above Java code as ReorderSlide.java, and then compile and execute
it from the command prompt as follows:
$javac ReorderSlide.java
$java ReorderSlide
39
Apache POI – PPT
Given below is the snapshot of the presentation before reordering the slides:
40
Apache POI – PPT
After reordering the slides, the presentation appears as follows. Here we have
selected the slide with image and moved it to the top.
Deleting Slides
You can delete the slides using the removeSlide() method. Follow the steps
given below to delete slides.
Delete the required slide using the removeSlide() method. This method
accepts an integer parameter. Pass the index of the slide that is to be deleted to
this method.
41
Apache POI – PPT
ppt.removeSlide(1);
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
//deleting a slide
ppt.removeSlide(1);
ppt.write(out);
42
Apache POI – PPT
out.close();
Save the above Java code as Deleteslide.java, and then compile and execute it
from the command prompt as follows:
$javac Deleteslide.java
$java Deleteslide
43
Apache POI – PPT
44
Apache POI – PPT
45
Apache POI – PPT
8. IMAGES
In this chapter, you will learn how to add an image to a PPT and how to read an
image from it.
Adding Image
You can add images to a presentation using the createPicture() method of
XSLFSlide. This method accepts image in the form of byte array format.
Therefore, you have to create a byte array of the image that is to be added to
the presentation.
Read the image file that is to be added and convert it into byte array using
IOUtils.toByteArray() of the IOUtils class as shown below:
//reading an image
Add the image to the presentation using addPicture(). This method accepts
two variables: byte array format of the image that is to be added and the static
variable representing the file format of the image. The usage of the
addPicture() method is shown below:
46
Apache POI – PPT
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFPictureData;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
//creating a presentation
//creating a slide in it
//reading an image
47
Apache POI – PPT
XSLFPictureData.PICTURE_TYPE_PNG);
ppt.write(out);
out.close();
Save the above Java code as AddingImage.java, and then compile and
execute it from the command prompt as follows:
$javac AddingImage.java
$java AddingImage
48
Apache POI – PPT
The presentation with the newly added slide with image appears as follows:
Reading Image
You can get the data of all the pictures using the getAllPictures() method of
the XMLSlideShow class. The following program reads the images from a
presentation:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
49
Apache POI – PPT
import org.apache.poi.xslf.usermodel.XSLFPictureData;
int pictureFormat=data.getPictureType();
ppt.write(out);
out.close();
50
Apache POI – PPT
Save the above Java code as Readingimage.java, and then compile and
execute it from the command prompt as follows:
$javac Readingimage.java
$java Readingimage
picture format: 6
51
Apache POI – PPT
9. CREATING HYPERLINKS
Creating Hyperlinks
You can read the hyperlinks in a presentation using the createHyperlink()
method of the XSLFTextRun class. Follow the procedure given below to create
a hyperlink in a presentation.
Create an empty slide and create a textbox and body of the slide using body and
content layout.
XSLFSlideLayout slidelayout =
slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
body.clearText();
XSLFTextRun textRun=body.addNewTextParagraph().addNewTextRun();
52
Apache POI – PPT
textRun.setText("Tutorials point");
Set the link address to the hyperlink using the setAddress() method of
XSLFHyperlink class as shown below:
link.setAddress("http://www.tutorialspoint.com/");
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
53
Apache POI – PPT
XSLFSlideLayout
slidelayout=slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
body.clearText();
textRun.setText("Tutorials point");
54
Apache POI – PPT
link.setAddress("http://www.tutorialspoint.com/");
ppt.write(out);
out.close();
Save the above Java code as CreatingHyperlinks.java, and then compile and
execute it from the command prompt as follows:
$javac CreatingHyperlinks.java
$java CreatingHyperlinks
55
Apache POI – PPT
The newly added slide with the hyperlink in its body looks as follows:
56
Apache POI – PPT
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
//get slides
57
Apache POI – PPT
XSLFShape[] sh = slide[i].getShapes();
System.out.println(sh[j].getShapeName());
ppt.write(out);
out.close();
Save the above Java code as ReadingShapes.java, and then compile and
execute it from the command prompt as follows:
$javac ReadingShapes.java
$java ReadingShapes
Rectangle 1
Oval 1
58
Apache POI – PPT
Isosceles Triangle 1
The newly added slide with the various shapes appears as follows:
59
Apache POI – PPT
XSLFSlideLayout slidelayout =
slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
body.clearText();
XSLFTextParagraph paragraph=body.addNewTextParagraph();
60
Apache POI – PPT
You can set the font size of the text in the presentation using setFontSize().
run.setFontColor(java.awt.Color.red);
run.setFontSize(24);
The following code snippet shows how to apply different formatting styles (bold,
italic, underline, strikeout) to the text in a presentation.
run.setBold(true);
run.setItalic(true)
run.setStrikethrough(true);
run.setUnderline(true);
paragraph.addLineBreak();
Given below is the complete program to format the text using all the above
methods:
61
Apache POI – PPT
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
XSLFSlideLayout slidelayout =
slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
62
Apache POI – PPT
body.clearText();
XSLFTextParagraph paragraph=body.addNewTextParagraph();
//formatting line1
run1.setFontColor(java.awt.Color.red);
run1.setFontSize(24);
paragraph.addLineBreak();
//formatting line2
63
Apache POI – PPT
run2.setFontColor(java.awt.Color.CYAN);
run2.setBold(true);
paragraph.addLineBreak();
//formatting line3
run3.setFontSize(12);
run3.setItalic(true);
run3.setStrikethrough(true);
paragraph.addLineBreak();
//formatting line4
run4.setUnderline(true);
64
Apache POI – PPT
paragraph.addLineBreak();
ppt.write(out);
out.close();
Save the above code as TextFormating.java, and then compile and execute it
from the command prompt as follows:
$javac TextFormating.java
$java TextFormating
65
Apache POI – PPT
66
Apache POI – PPT
12. MERGING
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
67
Apache POI – PPT
ppt.createSlide().importContent(srcSlide);
ppt.write(out);
out.close();
$javac MergingMultiplePresentations.java
$java MergingMultiplePresentations
68
Apache POI – PPT
69
Apache POI – PPT
Given below is the output of the program after merging the two slides. Here you
can see the content of the earlier slides merged together.
70
Apache POI – PPT
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
71
Apache POI – PPT
pgsize.height,BufferedImage.TYPE_INT_RGB);
graphics.setPaint(Color.white);
pgsize.height));
//render
slide[i].draw(graphics);
FileOutputStream("C://POIPPT//ppt_image.png");
ppt.write(out);
out.close();
Save the above Java code as PpttoPNG.java, and then compile and execute it
from the command prompt as follows:
$javac PpttoPNG.java
$java PpttoPNG
72
Apache POI – PPT
73
Apache POI – PPT
Given below is the snapshot of the image created at the specified location.
74