Help with transcoding SVG to PNG Batik 1.9

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help with transcoding SVG to PNG Batik 1.9

Al Pacifico
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with transcoding SVG to PNG Batik 1.9

Peter Coppens
Perhaps https://bz.apache.org/bugzilla/show_bug.cgi?id=44682 is the same ?

Try adding

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>batik-codec</artifactId>
    <version>1.9</version>
</dependency>

Hth

Peter


On 23 Jul 2017, at 16:27, Al Pacifico <[hidden email]> wrote:

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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help with transcoding SVG to PNG Batik 1.9

Al Pacifico
@Peter Coppens:  Thanks, your suggestion did the trick.  Somehow, I'm surprised by this, and I think this warrants fixing or mention in the documentation.

Cheers.
-Al

On Sun, Jul 23, 2017 at 7:43 AM, Peter Coppens <[hidden email]> wrote:
Perhaps https://bz.apache.org/bugzilla/show_bug.cgi?id=44682 is the same ?

Try adding

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>batik-codec</artifactId>
    <version>1.9</version>
</dependency>

Hth

Peter


On 23 Jul 2017, at 16:27, Al Pacifico <[hidden email]> wrote:

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.





--
Please forgive typo's, equally likely to have been typed on cell phone and to have been typed one-handed.

Loading...