Joe -

Don't save after every slide.

           //build the corrupt ppt
           System.out.print("Generating three slide ppt...");
           SlideShow pptFail = createPpt(FILE_NAME_FAIL);
           //create slide1
           pptFail.createSlide();
           //create slide2
           pptFail.createSlide();
           //create slide3
           pptFail.createSlide();
           savePpt(FILE_NAME_FAIL, pptFail);

See if that helps.

If not then do what Yegor says, create a Bugzilla and he will look into it when he has time.

Regards,
Dave

On Jan 21, 2010, at 11:14 AM, Joe Dente wrote:

Thanks for the response.

I find it very hard to believe that nobody's come across this issue
before, so I'm sure I am just doing something wrong such as not
releasing or closing an object or something. Here's a small java app
that demonstrates the problem. I've tried it with POI-3.2-FINAL (the
version I was intending to use) as well as POI-3.6 and the problem
exists in both versions. The main will generate two ppt presentations;
the 'twoSlides.ppt' deck is valid and the 'threeSlides.ppt' deck will be corrupt when you try and open them in PowerPoint. One interesting thing
to note is that if you generate 3 slides and then do a single save as
opposed to saving after creating every slide, the slide deck is not
corrupted. In our application, every time the user presses a button we
export his current context to a PowerPoint slide, which means we need to save the slide deck every time the user presses the button. The user can
press that button as many times as he wants to generate as many slides
as he wants in a session, and so I'm not sure what exactly to do about
this problem as far as our app is concerned.

Thanks for the help.
Joe

public class PoiPrototype {

   private static final String FILE_NAME_PASS = "twoSlides.ppt";

   private static final String FILE_NAME_FAIL = "threeSlides.ppt";

   public static SlideShow createPpt(String fileName) throws
IOException {
       //retrieve or create the presentation
       SlideShow ppt = null;

       File file = new File(fileName);
       if(file.exists()) {
           ppt = new SlideShow(new FileInputStream(file));
       } else {
           ppt = new SlideShow();
       }

       return ppt;
   }

   public static void savePpt(String fileName, SlideShow ppt) throws
FileNotFoundException, IOException {
       FileOutputStream out = new FileOutputStream(fileName);
       ppt.write(out);
       out.close();
   }

   public static void main(String[] args) {

       try {
           //build the non-corrupt ppt
           System.out.print("Generating two slide ppt...");
           SlideShow pptPass = createPpt(FILE_NAME_PASS);
           savePpt(FILE_NAME_PASS, pptPass);
           //create slide1
           pptPass.createSlide();
           savePpt(FILE_NAME_PASS, pptPass);
           //create slide2
           pptPass.createSlide();
           savePpt(FILE_NAME_PASS, pptPass);

           //build the corrupt ppt
           System.out.print("Generating three slide ppt...");
           SlideShow pptFail = createPpt(FILE_NAME_FAIL);
           //create slide1
           pptFail.createSlide();
           savePpt(FILE_NAME_FAIL, pptFail);
           //create slide2
           pptFail.createSlide();
           savePpt(FILE_NAME_FAIL, pptFail);
           //create slide3
           pptFail.createSlide();
           savePpt(FILE_NAME_FAIL, pptFail);

           System.out.println("COMPLETE");

       } catch(Throwable e) {
           System.err.println(e.getMessage());
           System.err.println(e);
       }
   }
}


-----Original Message-----
From: Yegor Kozlov [mailto:[email protected]]
Sent: Thursday, January 21, 2010 12:55 AM
To: POI Users List
Subject: Re: 3rd PowerPoint Slide is Corrupt

Does your code run on server side? I wonder if it is a concurrency
issue.

Which version of POI?

Can you create a bug in Bugzilla and attach sample code to reproduce the
problem (ideally a junit test case) and two ppt
files: one with two slides, not corrupted and the other with 3 slides,
corrupted.

Yegor

Hi,



I'm using the POI project to generate some PowerPoint slides. It works
fine until I generate the 3rd slide for my slide deck, which ends up
being corrupted every time. The first time my program runs it creates
a
new slide deck and adds a single slide to it. After that, every time
the
program runs it grabs the slide deck generated during the first run
and
appends a single slide to it. After the first run of the program the
slide deck is fine. After the second run it is fine as well. The third
run generates a corrupt slide every time. For testing purposes I
changed
my program so that all 3 runs of the program are generating the
identical blank slide and yet this corruption still happens, so it
does
not appear to have anything to do with my slide contents. I am
following
the code samples given on the POI website under "Shapes How To":



To create the slide deck during the first run:

SlideShow ppt = new SlideShow();



To connect to an existing slide deck during subsequent runs:

SlideShow ppt = null;

File pptFile = new File(pptFileName);

if(pptFile.exists()) {

   if(pptFile.canWrite()) {

   //construct the ppt from an existing file

      ppt = new SlideShow(new FileInputStream(pptFile));

   } else {

      throw new IOException("Unable to write to the PowerPoint file
'"
+ pptFileName + "'");

   }

}



To add a blank slide to the slide deck (nothing fancy here):

Slide slide = ppt.createSlide();



To save my slide deck after adding a slide:

FileOutputStream out = new FileOutputStream(pptFileName);

ppt.write(out);

out.close();



This all seems very straightforward and so I am not sure why the third
slide is always corrupted. Also, if I use my program to generate 2
slides and then I add a third slide through PowerPoint, I can continue
adding slides to the slide deck without any corruption. I can also
create a blank slide deck through PowerPoint and then use my program
to
append blank slides to the deck and no corruption happens. So this
leads
me to believe it has something to do with the saving of my PowerPoint
slide deck, since whenever I save it through PowerPoint the corruption
does not occur.



I appreciate any help.

Thanks in advance.

Joe




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to