Complete newbie to Batik here, so bear with me.

I am trying to transcode SVG's to PNG's using the following code:

package com.example;

import java.io.*;
import java.nio.file.Paths;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class Main {

    public static void main(String [] args) throws Exception {

        // read the input SVG document into TranscoderInput
        String svgURI = Paths.get(args[0]).toUri().toString();
        TranscoderInput input = new TranscoderInput(svgURI);
        // define OutputStream to PNG Image and attach to TranscoderOutput
        OutputStream ostream = new FileOutputStream("out.png");
        TranscoderOutput output = new TranscoderOutput(ostream);
        // create a JPEG transcoder
        PNGTranscoder t = new PNGTranscoder();
        // set the transcoding hints
        t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new Float(600));
        t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new Float(600));
        // convert and write output
        t.transcode(input, output);
        // flush and close the stream then exit
        ostream.flush();
        ostream.close();
    }
}

Compiled using Maven, this code repeatedly fails (using a variety of
SVG's) with the following exception.

Exception in thread "main" org.apache.batik.transcoder.TranscoderException:
null
Enclosed Exception:
Could not write PNG file because no WriteAdapter is availble
at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:132)
at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
at com.example.Main.main(Main.java:26)

After numerous Google searches, my theory is that the Maven repositories
are missing a dependency, but my brain says "blame yourself first," which
is why I am asking here.

Using the technique for listing dependencies outlined at
https://grep.codeconsult.ch/2010/07/08/list-all-your-maven-dependencies/, I
get the following list:
    commons-io:commons-io:jar:1.3.1
    commons-logging:commons-logging:jar:1.0.4
    junit:junit:jar:3.8.1
    org.apache.xmlgraphics:batik-anim:jar:1.9
    org.apache.xmlgraphics:batik-awt-util:jar:1.9
    org.apache.xmlgraphics:batik-bridge:jar:1.9
    org.apache.xmlgraphics:batik-constants:jar:1.9
    org.apache.xmlgraphics:batik-css:jar:1.9
    org.apache.xmlgraphics:batik-dom:jar:1.9
    org.apache.xmlgraphics:batik-ext:jar:1.9
    org.apache.xmlgraphics:batik-gvt:jar:1.9
    org.apache.xmlgraphics:batik-i18n:jar:1.9
    org.apache.xmlgraphics:batik-parser:jar:1.9
    org.apache.xmlgraphics:batik-script:jar:1.9
    org.apache.xmlgraphics:batik-svg-dom:jar:1.9
    org.apache.xmlgraphics:batik-svggen:jar:1.9
    org.apache.xmlgraphics:batik-transcoder:jar:1.9
    org.apache.xmlgraphics:batik-util:jar:1.9
    org.apache.xmlgraphics:batik-xml:jar:1.9
    org.apache.xmlgraphics:xmlgraphics-commons:jar:2.2
    xalan:serializer:jar:2.7.2
    xalan:xalan:jar:2.7.2
    xml-apis:xml-apis-ext:jar:1.3.04
    xml-apis:xml-apis:jar:1.3.04

Does anyone see a problem with my code?
-Al
-- 
Please forgive typo's, equally likely to have been typed on cell phone and
to have been typed one-handed.

Reply via email to