1 17 18 19 20 package org.apache.fop.plan; 21 22 import java.io.InputStream ; 23 import java.io.Writer ; 24 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 28 import org.apache.batik.transcoder.svg2svg.SVGTranscoder; 29 import org.apache.batik.transcoder.TranscoderInput; 30 import org.apache.batik.transcoder.TranscoderOutput; 31 32 35 public class Main { 36 37 41 public static void main(String [] args) { 42 Main main = new Main(); 43 main.convert(args); 44 System.exit(0); 45 } 46 47 51 public void convert(String [] params) { 52 if (params.length != 2) { 53 System.out.println("arguments: plan.xml output.svg"); 54 return; 55 } 56 try { 57 InputStream is = new java.io.FileInputStream (params[0]); 58 Document doc = createSVGDocument(is); 59 SVGTranscoder svgT = new SVGTranscoder(); 60 TranscoderInput input = new TranscoderInput(doc); 61 Writer ostream = new java.io.FileWriter (params[1]); 62 TranscoderOutput output = new TranscoderOutput(ostream); 63 svgT.transcode(input, output); 64 ostream.flush(); 65 ostream.close(); 66 67 } catch (Exception e) { 68 e.printStackTrace(); 69 } 70 } 71 72 77 public Document createSVGDocument(InputStream is) { 78 Document doc = null; 79 80 Element root = null; 81 try { 82 doc = javax.xml.parsers.DocumentBuilderFactory.newInstance(). 83 newDocumentBuilder().parse(is); 84 85 root = doc.getDocumentElement(); 86 87 } catch (Exception e) { 88 e.printStackTrace(); 89 } 90 PlanRenderer gr = new PlanRenderer(); 91 gr.setFontInfo("sansserif", 12); 92 Document svgdoc = gr.createSVGDocument(doc); 93 return svgdoc; 94 } 95 } 96 | Popular Tags |