Return-Path: Delivered-To: apmail-poi-user-archive@www.apache.org Received: (qmail 39758 invoked from network); 21 Jan 2010 22:17:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jan 2010 22:17:28 -0000 Received: (qmail 88796 invoked by uid 500); 21 Jan 2010 22:17:27 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 88766 invoked by uid 500); 21 Jan 2010 22:17:27 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 88756 invoked by uid 99); 21 Jan 2010 22:17:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 22:17:27 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_HELO_PASS,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.86.168.182] (HELO mxout-07.mxes.net) (216.86.168.182) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 22:17:19 +0000 Received: from [192.168.1.104] (unknown [67.180.32.178]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id D544C22E253 for ; Thu, 21 Jan 2010 17:16:56 -0500 (EST) Message-Id: <9F3BDF74-A592-4C36-AF7F-B496EB7AA5B9@jmlafferty.com> From: David Fisher To: "POI Users List" In-Reply-To: <54D41E91F26CF6488C7088C89D9160F8019436FA@21ctexg01.21technologies.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: 3rd PowerPoint Slide is Corrupt Date: Thu, 21 Jan 2010 14:16:54 -0800 References: <54D41E91F26CF6488C7088C89D9160F80194342C@21ctexg01.21technologies.com> <4B57FA45.4000208@dinom.ru> <54D41E91F26CF6488C7088C89D9160F801943663@21ctexg01.21technologies.com> <4973B0E9-FF48-4EAE-A0F6-6E9752C503E2@jmlafferty.com> <54D41E91F26CF6488C7088C89D9160F8019436FA@21ctexg01.21technologies.com> X-Mailer: Apple Mail (2.936) 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