Apache POI PPT Slide Management Apache POI PPT

What is the use of Slide management in Apache POI PPT?

By the time you complete this chapter, users will be able to delete/reorder and perform read and write operations on a slide.

Changing a Slide

Page size of a slide can be changed by using setPageSize() method of the XMLSlideShow class.

Initially create a presentation as shown below:

You can get the size of the current slide using getPageSize() method of the XMLSlideShow class.

You can set the size of the page using setPageSize() method.

Complete program for changing the size of a slide is given below:

Save the above Java code as ChangingSlide.java and then compile and execute it from the command prompt as shown below:

It will compile and execute to generate below output.

Below is the snapshot of the presentation before changing the slide size:

TitleAndContentLayout

Slide appears as follows after changing its size:

slideAfterChange

Reordering Slides

You can set the slide order using the setSlideOrder() method by following below procedure

Open an existing PPT document as shown below:

You can get the slides using the getSlides() method as shown below:

Select a slide from the array of the slides and change the order using setSlideOrder() method as shown below:

Below is the complete program to reorder the slides in a presentation:

Save the above Java code as ReorderSlide.java and then compile and execute it from the command prompt as shown below:

It will compile and execute to generate below output.

Given below is the snapshot of the presentation before reordering the slides:

before recorder

After reordering the slides, presentation will appear as shown below. Here we have selected the slide with image and moved it to the top.

Recording slides

Deleting Slides

You can delete the slides using removeSlide() method. Follow the steps given below for deleting slides.

Open an existing presentation using the XMLSlideShow class as shown below:

You can delete the required slide using removeSlide() method. This method will accept an integer parameter. You can pass the index of the slide which has to be deleted to this method.

Below is the program to delete slides from a presentation:

Save the above Java code as Deleteslide.java and then compile and execute it from the command prompt as shown below:

It will compile and execute to generate below output:

Below screenshot is the presentation before deleting the slide:

Before-Reorder

After deleting the slide, presentation will appear as shown below:

delete slides

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache POI PPT Topics