BatikPostScriptPP

Hi,

  The following is a very simple example using Batik to execute the
onload scripts in a document and write the resulting document tree to
stdout.

  import java.io.OutputStreamWriter;
  import org.w3c.dom.Document;
  import org.apache.batik.bridge.BaseScriptingEnvironment;
  import org.apache.batik.bridge.BridgeContext;
  import org.apache.batik.bridge.GVTBuilder;
  import org.apache.batik.bridge.UserAgentAdapter;
  import org.apache.batik.transcoder.svg2svg.SVGTranscoder;
  import org.apache.batik.transcoder.TranscoderInput;
  import org.apache.batik.transcoder.TranscoderOutput;
  import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  import org.apache.batik.util.XMLResourceDescriptor;
  
  public class BatikPostScriptPP
  {
      void run() throws Exception
      {
          String parser = XMLResourceDescriptor.getXMLParserClassName();
          SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
          String uri = "http://...";
          Document doc = f.createDocument(uri);
  
          UserAgentAdapter userAgent = new UserAgentAdapter();
          GVTBuilder builder         = new GVTBuilder();
          BridgeContext ctx          = new BridgeContext(userAgent);
          ctx.setDynamic(true);
  
          builder.build(ctx, doc);
          BaseScriptingEnvironment scriptEnvironment 
              = new BaseScriptingEnvironment(ctx);
  
          scriptEnvironment.loadScripts();
          scriptEnvironment.dispatchSVGLoadEvent();
  
          SVGTranscoder p       = new SVGTranscoder();
          TranscoderInput in    = new TranscoderInput(doc);
          OutputStreamWriter ow = new OutputStreamWriter(System.out);
          TranscoderOutput out  = new TranscoderOutput(ow);
  
          p.transcode(in, out);
      }
  
      public static void main(String[] args) throws Exception
      {
          (new BatikPostScriptPP()).run();
      } 
  }

regards.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Tuesday, 15 March 2005 23:47:02 UTC