poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Dente" <jde...@21technologies.com>
Subject RE: 3rd PowerPoint Slide is Corrupt
Date Thu, 21 Jan 2010 23:59:50 GMT
The suggestion to re-open the slideshow after every save was made
earlier. I attempted to do that in the prototype (and actually my
project's code does re-open the file every time) and it had no effect.
The problem still occurred. The way I am re-opening a file is basically
instantiating a new SlideShow around a new File pointing to the same
path every time the program executes. Basically modify the code in the
prototype so that it looks like:

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

            System.out.println("COMPLETE");

Is there something I need to do to release the previous SlideShow before
I can re-open? For example, do I need to do anything with the
FileInputStream or File handles that I used to construct the SlideShow
(I assumed the stream would be closed after the SlideShow construction)?

Thanks,
Joe

-----Original Message-----
From: David Fisher [mailto:dfisher@jmlafferty.com] 
Sent: Thursday, January 21, 2010 4:17 PM
To: POI Users List
Subject: Re: 3rd PowerPoint Slide is Corrupt

Joe,

The workaround for your use case is to re-open the SlideShow after  
every save.

According to comments I have seen in the past saving does things to  
the SLideShow such that it not really safe to do multiple times.

Regards,
Dave

On Jan 21, 2010, at 1:25 PM, Joe Dente wrote:

> A bug has been filed
> (https://issues.apache.org/bugzilla/show_bug.cgi?id=48593).
>
> As explained, saving after every slide is created was done simply to
> demonstrate the bug. If I delay the save until all 3 slides are  
> created,
> the problem does not exist. However, this is not an option. The action
> is there for the user to generate a new PowerPoint slide. So we create
> the slide and then we need to save it because the user probably  
> wants to
> go look at his new slide. This workflow is fine up until the 3rd  
> slide,
> which is suddenly corrupt.
>
> I appreciate all of your help. Hopefully it's an easy fix or maybe
> somebody else out there sees a problem with my sample code.
> Thanks,
> Joe
>
>
>
> -----Original Message-----
> From: David Fisher [mailto:dfisher@jmlafferty.com]
> Sent: Thursday, January 21, 2010 1:42 PM
> To: POI Users List
> Subject: Re: 3rd PowerPoint Slide is Corrupt
>
> 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:yegor@dinom.ru]
>> 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: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message