xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincent Hardy <vha...@eng.sun.com>
Subject Re: Exception: fragment ist not an XML Document
Date Fri, 02 Feb 2001 01:32:32 GMT
Mariano,

I forgot to mention something: I assume you have a need to keep the 
SVG you generate with the SVGGraphics2D other than generating the
JPEG. If you do not, you would not need to go through SVG at all 
and could use a BufferedImage, draw into it, and save it as JPEG.

V.

Vincent Hardy wrote:
> 
> Mariano,
> 
> Mariano Kamp wrote:
> >
> > Hi there,
> >
> >   first of all I'd like to know how I can access an archive of this
> > list? There are loads of mailing list archives on the site, but not for
> > this list.
> 
> We are trying. I hope this will be resolved in the coming month.
> In the meanwhile:
> 
> http://www.inria.fr/koala/batik
> 
> >
> >   I want to draw a Chart on a java graphics object and then transform it
> > to svg and from there to a jpeg. The first steps are working alright. What
> > is not working for me is the conversion from the svg graphics object to
> > the jpeg image.
> >
> >   What is the right way of doing this? Currently I am asking the
> > SVGGraphics2D with getDOMFactory() for the Document and then try to pass
> > it as parameter to TranscoderInput. After that I pass the TranscoderInput
> > Object to the transcode() Method. When outputing the tree with
> > stream() the document looks good (complete) to me, but when the transcode
> > Method
> > tells me: The specified Document fragment is not an SVG document.
> >
> > Any clues?
> 
> I have attached a sample file that does what you want. I hope this will
> help.
> 
> Cheers & good luck with Batik!
> V.
> 
> >
> > Mariano
> >
> > --
> > mariano kamp
> > codamax ag
> > hessenring 89
> >
> > 61348 bad homburg v.d.h.
> > germany
> >
> > phone  +49 6172 182 473
> > fax    +49 6172 182 475
> > mobile +49 177 727 9468
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> 
>   ------------------------------------------------------------------------
> /*****************************************************************************
>  * Copyright (C) The Apache Software Foundation. All rights reserved.        *
>  * ------------------------------------------------------------------------- *
>  * This software is published under the terms of the Apache Software License *
>  * version 1.1, a copy of which has been included with this distribution in  *
>  * the LICENSE file.                                                         *
>  *****************************************************************************/
> 
> import org.apache.batik.dom.svg.SVGDOMImplementation;
> import org.apache.batik.svggen.SVGGraphics2D;
> import org.apache.batik.transcoder.image.JPEGTranscoder;
> import org.apache.batik.transcoder.TranscoderInput;
> import org.apache.batik.transcoder.TranscoderOutput;
> import org.apache.batik.transcoder.TranscoderException;
> 
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> import org.w3c.dom.DOMImplementation;
> 
> import java.awt.Color;
> import java.awt.Dimension;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.OutputStreamWriter;
> 
> /**
>  * An example showing how to:
>  *  a) Use SVGGraphics2D to generate a DOM tree
>  *  b) Use the generated DOM tree as an input to a transcoder, JPEG
>  *     in this example.
>  *
>  * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
>  * @version $Id$
>  */
> public class JavaToSvgToJpeg {
>     public static final String USAGE = "java JavaToSvgJpeg <outputJpegFileName>";
> 
>     public static void main(String args[]) throws Exception{
>         if(args.length < 1){
>             System.err.println(USAGE);
>             System.exit(0);
>         }
> 
>         //
>         // Build SVGGraphics2D with Batik's DOM implementation
>         //
>         DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
>         String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
>         Document doc = impl.createDocument(namespaceURI, "svg", null);
>         SVGGraphics2D g = new SVGGraphics2D(doc);
> 
>         //
>         // Draw something
>         //
>         g.setPaint(Color.black);
>         g.fillRect(0, 0, 300, 300);
>         g.setPaint(Color.white);
>         g.fillOval(20, 20, 260, 260);
> 
>         // g.stream(new OutputStreamWriter(System.out));
> 
>         //
>         // Set document size
>         //
>         doc.getDocumentElement().setAttributeNS(null, "width", "300");
>         doc.getDocumentElement().setAttributeNS(null, "height", "300");
> 
>         //
>         // Set document content
>         //
>         doc.getDocumentElement().appendChild(g.getRoot());
> 
>         //
>         // Convert to JPEG
>         //
>         TranscoderInput svgInput = new TranscoderInput(doc);
>         JPEGTranscoder jpegTranscoder = new JPEGTranscoder();
>         jpegTranscoder.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
>                                          "org.apache.crimson.parser.XMLReaderImpl");
>         jpegTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
>                                           new Float(1));
> 
>         // First, transcode image
>         File imageFile = new File(args[0]);
> 
>         TranscoderOutput imageOutput =
>             new TranscoderOutput(new FileOutputStream(imageFile));
> 
>         jpegTranscoder.transcode(svgInput, imageOutput);
>     }
> }
> 
>   ------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org

Mime
View raw message