Hugh,
You are using the right approach. You need to do:
Element root = document.getDocumentElement();
// The following populates the document root with the
// generated SVG content.
sg.getRoot(root);
before you use it in the transcoder, but then, it should work.
Vincent.
Hugh Eland wrote:
> Hi,
>
> I am trying to use SVGGraphics2D to create a DOM document, which I will then output
>in various formats in my application.
> The below code always produces a
>
> Error in transcoder org.apache.batik.transcoder.TranscoderException: The specified
>XML document fragment is not an SVG document
>
>>From reading the newsgroups I now understand that the document is only used as a
>factory, and not populated by the SVGraphics.
>
> I have tried following the stuff on the new getRoot() method (
>http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9520 ) but don't immediately see
>how this helps...
>
> Is this the wrong approach? - I want the graphics stored in DOM document so I can
>output in different forms...
>
> (Tried with Batik 1.5b3 and JDK1.4)
>
> Cheers
>
> Hugh
>
> SVGGraphics2D sg;
> DOMImplementation domImpl = // Get a DOMImplementation
> GenericDOMImplementation.getDOMImplementation();
>
> // Create an instance of org.w3c.dom.Document
> String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> Document document = domImpl.createDocument(svgNS, "svg", null);
>
> // Create an instance of the SVG Generator
> sg = new SVGGraphics2D(document);
>
> // Draw the image
> drawGraphics(sg);
>
> try
> {
> JPEGTranscoder t = new JPEGTranscoder();
> t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
> new Float(.8));
> TranscoderInput input = new TranscoderInput(document);
> TranscoderOutput output = new TranscoderOutput(ostream);
> t.transcode(input, output);
> return true;
> }
>
> ---------------------------------------------------------------------
> 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]