You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Hugh Eland <hu...@2020media.com> on 2002/08/10 18:30:11 UTC
SVGGraphics2D to create a DOM document
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: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: SVGGraphics2D to create a DOM document
Posted by Vincent Hardy <vi...@sun.com>.
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: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org