Much thanks, Thanks to your help I finally got the program working

Ruben Malchow wrote:
> 
> 
> 
> hello milof,
> 
> i use the following code (standard DOM serialization), and it works brill:
> 
>       TransformerFactory tf = TransformerFactory.newInstance();
>       Transformer transformer = tf.newTransformer();
>       Result outputTarget = new StreamResult(os);
>       Source xmlSource = new DOMSource(svgdoc);
>       transformer.setOutputProperty(OutputKeys.METHOD, "xml");
>       transformer.setOutputProperty(
>               OutputKeys.CDATA_SECTION_ELEMENTS,"");
>       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
>       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
>       transformer.setOutputProperty(
>               "{http://xml.apache.org/xslt}indent-amount";, "2");
>       transformer.transform(xmlSource, outputTarget);
> 
> 
> .rm
> 
> 
> milof schrieb:
>> hi, 
>> I am a beginner batik user and at the moment I am working on apiece of
>> code
>> which would allow me to open svg file edit it and save it as an svg file.
>> 
>> I have sucessfully loaded svg file (thanks to thomas.deweese) and
>> currently
>> I'm facing a problem with saving it to an svg file.
>> 
>> Below is the sourcecode for the function which is supposed to do the
>> task.
>> 
>> public void editSVG (String inputFilename, String outputFilename) throws
>> Exception {
>>     
>>              String svgURI = new File(inputFilename).toURL().toString();
>>              
>>              try{
>>              UserAgentAdapter ua = new UserAgentAdapter(); 
>>                DocumentLoader loader = new DocumentLoader(ua); 
>>                Document doc = loader.loadDocument(svgURI);
>>         
>>              // get the root element (the svg element)
>>              Element svgRoot = doc.getDocumentElement();
>>              
>>              // set the width and height attribute on the root svg element
>>              svgRoot.setAttributeNS(svgURI, "width", "400");
>>              svgRoot.setAttributeNS(svgURI, "height", "330");
>>                              
>>              // create the rectangle
>>              Element rectangle = doc.createElementNS(svgNS, "rect");
>>              rectangle.setAttributeNS(null, "x", "200");
>>              rectangle.setAttributeNS(null, "y", "200");
>>              rectangle.setAttributeNS(null, "width", "100");
>>              rectangle.setAttributeNS(null, "height", "100");
>>              rectangle.setAttributeNS(null, "fill", "red");
>> 
>>              // attach the rectangle to the svg root element
>>              svgRoot.appendChild(rectangle);
>>              
>>              TranscoderInput input = new TranscoderInput(doc);
>>                OutputStream ostream = new
>> FileOutputStream(outputFilename);
>>                TranscoderOutput output = new TranscoderOutput(ostream);
>>                svgTrans.transcode(input, output);
>>                ostream.flush();
>>                ostream.close();
>>              
>>              System.out.println("SVG edited");
>>              } catch (Exception e){
>>                      System.out.println("Error: " + e);
>>              }
>>     }
>> 
>> The error message i'm recieving during the program runtime:
>> 
>> Exception in thread "main" java.lang.Error: Writer expected
>>      at org.apache.batik.transcoder.svg2svg.SVGTranscoder.transcode(Unknown
>> Source)
>>      at SVGtoJPEG.editSVG(SVGtoJPEG.java:96)
>>      at SVGtoJPEG.main(SVGtoJPEG.java:112)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/beginner%3A-saving-file-as-svg-tf2128083.html#a5903245
Sent from the Batik - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to