Demos > Persentation Extraction and Combination


To show the operation of Presentation in Simple API, the Presentation Codmbination demo is used which combine two independent presentation documents together and extract the notes of each slide out to a Text document.

Here the original presentation documents "Pres1.odp" and "Pres2.odp" are used. Pres1.odp presents some basic concepts of XML and Pres2.odp presents some basic aspects of HTML. Both of them have their own cover page with the same slide name "Cover" at the front and an End page with the same slide name "end" at the end of the document. To combine these two presentation documents together, the following steps are used here.

  1. Delete the last page of "Pres1.odp".
  2. Change the slide name of the cover page for each presentation document.
  3. Append "Pres2.odp" to the end of "Pres1.odp".
  4. Add a new slide at the front of the combined presentation document as the new cover page.
  5. Add title and notes to the new cover page.
  6. Extract the notes from each slide in the presentation document and save them into a text document.
  7. Save the combined document and the text document.

The contents of the text document which contains the notes of the presentation document is shown in the following picture, where each note is identified by the corresponding slide name.

Code Introduction

To generate this sample, the Presentation and Text package in Simple API will be used. The related operations contains: load the existing presentation document, append one presentation to the end of another one, delete slide in the presentation, add new slide in the presentation, get certain slide in the presentation, add new notes to the slide, create a new text document, add new paragraph in the text document, etc.

Seven functions exist in the resource: main(), Getpresentation(), ProcSlide(), titleofExtractnotes(), ExtractNotes(), FillExtractnotes() and saveDocument(). Each of them will be explained briefly in the following paragraphs.

First three variables should be used to hold the two presentation document and the text document.

PresentationDocument presentationdoc;
PresentationDocument presentationdoc2;
TextDocument Extractednotes;

In function Getpresentation(), the two presentation documents are loaded so that they can be operated by Simple API, and the text document is created to save the extracted notes. The codes are shown below:

public void Getpresentation() {
    try {
    } catch (Exception e) {
        System.err.println("Unable to load document.");

    } catch (Exception e) {
        System.err.println("Unable to create text document.");

In function ProcSlide(), five main operations are used to process the document: delete extra slide (deleteSlideByIndex, deleteSlideByName), change slide name (setSlideName), combine these two presentations together (appendPresentation), add a new cover for the new combined document (newSlide), add title and notes for the new slide. Here the function getSlideCount() is used to get the slide number of the specified presentation document, getSlideByName()and getSlideByIndex() are used to get the specified slide, getNotesPage() and setTextContent() are used to add notes for the added slide. In order to add text to the title frame, a DrawTextBoxElement should be used to get the editable component. The codes are shown below:

Slide slide;
Notes notes;
int count=presentationdoc.getSlideCount();
slide.setSlideName("XML Cover");
slide.setSlideName("HTML Cover");
slide=presentationdoc.newSlide(0, "Cover", SlideLayout.TITLE_ONLY); 
notes.addText("This is the cover of the new presentation document");
DrawTextBoxElement textbox=(DrawTextBoxElement)slide.getOdfElement().getFirstChild().getFirstChild();
textbox.newTextPElement().setTextContent("Combined Presentation");

In function titleofExtractnotes(), the title of the text document which is used to save the notes of each slide is added. And in function ExtractNotes(), the notes of each slide will be extracted (getTextContent), the function FillExtractnotes() will be called if the notes exists. Here function getSlideByIndex() is used to obtain the corresponding slide, getSlideName() is used to obtain the name of the specified slide in order to identify the notes. The codes are shown below:

String slidename=slide.getSlideName();
    String notestring=notes.getOdfElement().getTextContent().toString().trim();

In function FillExtractnotes, the notes will be added to the text document. Here the slide name is used as the identity and is followed by the corresponding notes, function newParagraph() is used to add a new paragraph in the text document. The codes are shown below:

OdfTextParagraph para =Extractednotes.newParagraph();
para.setProperty(OdfParagraphProperties.MarginTop, "0.25cm");
para.setTextContent("Notes of "+slidename+":");             
para.setTextContent("  "+notestext);

In function saveDocument(), the new combined presentation document and the text document which contains the notes will be saved. The codes are shown below:

public void saveDocument(){     
    }catch(Exception e){
        System.err.println("Unable to save document.");


Powered by Simple API version 0.3.5.
You can download the code of this sample from here.

Powered by the Apache CMS.

Apache "ODF Toolkit" is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2011 The Apache Software Foundation Licensed under the Apache License, Version 2.0. Contact Us
Apache and the Apache feather logos are trademarks of The Apache Software Foundation.
Other names appearing on the site may be trademarks of their respective owners.