Demos > Multiple Presentations Assembler


If you make a lot of presentations in your daily work, you know that you don't always create a presentation from scratch.

Assembling several different presentations together to make a new presentation, e.g. copying several pages from presentation A and copying another several pages from presentation B, is a common activity for the presentation author. This demo provides a Java application that can assemble specific pages of presentations together and make one presentation from the command line.

Here is an example. I want to make a presentation with the first page from presentation A, the first page from presentation B and the first page from presentation C. I can call the following command:

java PresentationAssembler -in PresentationA.odp(1) -in PresentationB.odp(1) -in PresentationC.odp(1-2) -out newPresentation.odp

A new presentation will be generated which is showed in the following picture. You can see, the pictures, the styles and master pages are copied too.

alt text

In the next section, I will show how easy it is to create this assembling application using the Simple API.

Code Introduction

assemble is the method that accepts the command line parameters, analyzes them, and assembles presentations with the Simple API. In this method, a new presentation is created, and then, pages from other presentation documents are attached while the command line is being analyzed. Simple API provides very simple methods to copy pages from other presentations: PresentationDocument.copyForeignSlide(int destIndex, PresentationDocument srcDoc, int srcIndex) and PresentationDocument.appendPresentation(PresentationDocument srcDoc).

After the slides are attached, the first slide of the new presentation is deleted by invoking method PresentationDocument.deleteSlideByIndex(int index).

This is because the first slide is an empty slide which was created when the new presentation was created with method PresentationDocument.newPresentationDocument()

Below is the source code of method assemble. Most of the code is used to analyze the command line parameters. Only a few statements are used to attach slides to the new presentation. So you can see how powerful functions Simple API provides.

public void assemble(String[] args) throws Exception
    String outputFileName="default.odp";
    int pageIndex = 1;
    PresentationDocument doc = PresentationDocument.newPresentationDocument();
    int i=0;
    while (i < args.length)
        String param = args[i];
        if (param.equals("-out")) //get the output file name
            outputFileName = args[++i];
        else if (param.equals("-in")) //get the input file name 
            String pageDesc = args[++i];
            String filename = pageDesc, pagelist;
            int indexStart = pageDesc.indexOf('('); //get the page numbers
            int[] srcPages = null;
            if (indexStart > -1)
                filename = pageDesc.substring(0, indexStart);
                pagelist = pageDesc.substring(indexStart+1, pageDesc.length()-1);
                srcPages = getPageNumbers(pagelist); //analysis the page number description 
                                                     //and return all page numbers that need to be copied
            PresentationDocument sourceDoc = PresentationDocument.loadDocument(new File(filename));
            if (srcPages==null)
                pageIndex += sourceDoc.getSlideCount();
            } else for(int j=0;j < srcPages.length;j++)
                doc.copyForeignSlide(pageIndex, sourceDoc, srcPages[j]);


Powered by the Simple Java API for ODF version 0.4.5.
You can download the code of this demo 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.