Hi Jonathan,
thanks for this code. It works perfectly! Now I have to investigate deeply, step by step, why my code fails. Fortunately I can eliminate Batik side. Sorry for this noise. Regards, Jan From: jonathan wood [mailto:jonathanshaww...@gmail.com] Sent: Thursday, February 25, 2010 6:25 PM To: batik-users@xmlgraphics.apache.org Subject: Re: Creating an image on the fly from a servlet Here's a distilled version of a servlet that works for me. I can post the associated NB web project (sans libs) if there is any interest. jsw protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); ServletOutputStream out = response.getOutputStream(); try { PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(100)); TranscoderInput input = new TranscoderInput(SVG2PNGServlet.class.getResourceAsStream("batikLogo.svg")); TranscoderOutput output = new TranscoderOutput(out); t.transcode(input, output); } catch (TranscoderException ex) { Logger.getLogger(SVG2PNGServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } } 2010/2/23 Jan Tosovsky <j.tosov...@tiscali.cz> > I havent tried to duplicate using your code, but I do notice that my servlet > transcodes always set the content type before obtaining the sevlet output stream: > > response.setContentType("image/png"); Actually, this line precedes my lines below ;-) But good to know it works somewhere else in the servlet environment (are you really able to save the result image?) so it seems to be my fault. I would be grateful for a link to any working example code... I hope there is no any special magic behind, just a small mistake from my side... On Tue, Feb 23, 2010 at 2:11 PM, Jan Tosovsky <j.tosov...@tiscali.cz> wrote: > > Although I can see the result in the target browser, I am unable to > save the > > image on a local disk. Actually, in Firefox I can notice an attempt > to save > > the file, but in a download manager it is of zero size and it is not > really > > present in the target location. MSIE offers me save the PNG file in > BMP > > format... > > The fact that you can see it and cannot save it very weird. Even > weirder is the described MSIE behavior. If you are working with the > trunk code, maybe your are getting bit by bug 48693 [1]? If you are > working with Batik 1.7, that may be bug 46863 [2]. Thanks for this info. It led me to try also JPEG output, but the result is the same. I suspect the way of closing the final stream. I think the browser can display partial data but as they are unfinished properly, it made him puzzled a bit. Transcoding via command line is Ok in all cases. > Could you try to analyze the (supposedly PNG) raw file saved and/or > attach it to a reply? No file is created in FF so there is nothing to analyze. And that MSIE BMP file is the standard image. It is probably a kind of the screenshot of an internal canvas. Here is the final part of my code: TranscoderOutput output = new TranscoderOutput(response.getOutputStream()); t.transcode(input, output); // I've tried to find any closing method of the 'output' object, // but still without success. The following way also doesn't help // // output.getWriter().close(); ServletOutputStream out = response.getOutputStream(); out.flush(); out.close(); Any other ideas? Jan > Hope this helps, > Helder > > > [1] https://issues.apache.org/bugzilla/show_bug.cgi?id=48693 > [2] https://issues.apache.org/bugzilla/show_bug.cgi?id=46863 --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org