Re: Help with transcoding SVG to PNG Batik 1.9

Al Pacifico <[email protected]> Sun, 23 Jul 2017 08:06:40 -0700
Newsgroups gmane.text.xml.batik.user
Message-ID <CAGRVsLvG7i13MuadzF6tcKfMWePFp3eVfk+vZFH8Vh0J4pWzbQ@mail.gmail.com>
--94eb2c1b048a19b8370554fd72bf
Content-Type: text/plain; charset="UTF-8"

@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 <[email protected]>
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 <[email protected]> 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.

--94eb2c1b048a19b8370554fd72bf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">@Peter Coppens: =C2=A0Thanks, your suggestion did the tric=
k.=C2=A0 Somehow, I&#39;m surprised by this, and I think this warrants fixi=
ng or mention in the documentation.<div><br></div><div>Cheers.</div><div>-A=
l</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On S=
un, Jul 23, 2017 at 7:43 AM, Peter Coppens <span dir=3D"ltr">&lt;<a href=3D=
"mailto:[email protected]" target=3D"_blank">pc.subscriptions@gmai=
l.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=3D=
"word-wrap:break-word">Perhaps=C2=A0<a href=3D"https://bz.apache.org/bugzil=
la/show_bug.cgi?id=3D44682" target=3D"_blank">https://bz.apache.org/<wbr>bu=
gzilla/show_bug.cgi?id=3D44682</a><wbr>=C2=A0is the same ?<div><br></div><d=
iv>Try adding</div><div><br></div><div><div>&lt;dependency&gt;</div><div>=
=C2=A0 =C2=A0 &lt;groupId&gt;org.apache.<wbr>xmlgraphics&lt;/groupId&gt;</d=
iv><div>=C2=A0 =C2=A0 &lt;artifactId&gt;batik-codec&lt;/<wbr>artifactId&gt;=
</div><div>=C2=A0 =C2=A0 &lt;version&gt;1.9&lt;/version&gt;</div><div>&lt;/=
dependency&gt;</div><div><br></div><div>Hth</div><span class=3D"HOEnZb"><fo=
nt color=3D"#888888"><div><br></div><div>Peter</div></font></span><div><div=
 class=3D"h5"><div><br></div><div><br><div><blockquote type=3D"cite"><div>O=
n 23 Jul 2017, at 16:27, Al Pacifico &lt;<a href=3D"mailto:[email protected]=
om" target=3D"_blank">[email protected]</a>&gt; wrote:</div><br class=3D"m=
_6462938449863425286Apple-interchange-newline"><div><div dir=3D"ltr">Comple=
te newbie to Batik here, so bear with me.<div><br></div><div>I am trying to=
 transcode SVG&#39;s to PNG&#39;s using the following code:</div><div><pre =
style=3D"font-family:&#39;DejaVu Sans Mono&#39;;font-size:11.3pt"><span sty=
le=3D"color:rgb(0,0,128);font-weight:bold">package </span>com.example;<br><=
br><span style=3D"color:rgb(0,0,128);font-weight:bold">import </span><a hre=
f=3D"http://java.io" target=3D"_blank">java.io</a>.*;<br><span style=3D"col=
or:rgb(0,0,128);font-weight:bold">import </span>java.nio.file.Paths;<br><sp=
an style=3D"color:rgb(0,0,128);font-weight:bold">import </span>org.apache.b=
atik.transcoder.<wbr>image.PNGTranscoder;<br><span style=3D"color:rgb(0,0,1=
28);font-weight:bold">import </span>org.apache.batik.transcoder.<wbr>SVGAbs=
tractTranscoder;<br><span style=3D"color:rgb(0,0,128);font-weight:bold">imp=
ort </span>org.apache.batik.transcoder.<wbr>TranscoderInput;<br><span style=
=3D"color:rgb(0,0,128);font-weight:bold">import </span>org.apache.batik.tra=
nscoder.<wbr>TranscoderOutput;<br><br><span style=3D"color:rgb(0,0,128);fon=
t-weight:bold">public class </span>Main {<br><br>    <span style=3D"color:r=
gb(0,0,128);font-weight:bold">public static void </span>main(String [] args=
) <span style=3D"color:rgb(0,0,128);font-weight:bold">throws </span>Excepti=
on {<br><br>        <span style=3D"color:rgb(128,128,128);font-style:italic=
">// read the input SVG document into TranscoderInput<br></span><span style=
=3D"color:rgb(128,128,128);font-style:italic">        </span>String svgURI =
=3D Paths.<span style=3D"font-style:italic">get</span>(args[<span style=3D"=
color:rgb(0,0,255)">0</span>]).toUri().<wbr>toString();<br>        Transcod=
erInput input =3D <span style=3D"color:rgb(0,0,128);font-weight:bold">new <=
/span>TranscoderInput(svgURI);<br>        <span style=3D"color:rgb(128,128,=
128);font-style:italic">// define OutputStream to PNG Image and attach to T=
ranscoderOutput<br></span><span style=3D"color:rgb(128,128,128);font-style:=
italic">        </span>OutputStream ostream =3D <span style=3D"color:rgb(0,=
0,128);font-weight:bold">new </span>FileOutputStream(<span style=3D"color:r=
gb(0,128,0);font-weight:bold">&quot;out.png&quot;</span>);<br>        Trans=
coderOutput output =3D <span style=3D"color:rgb(0,0,128);font-weight:bold">=
new </span>TranscoderOutput(ostream);<br>        <span style=3D"color:rgb(1=
28,128,128);font-style:italic">// create a JPEG transcoder<br></span><span =
style=3D"color:rgb(128,128,128);font-style:italic">        </span>PNGTransc=
oder t =3D <span style=3D"color:rgb(0,0,128);font-weight:bold">new </span>P=
NGTranscoder();<br>        <span style=3D"color:rgb(128,128,128);font-style=
:italic">// set the transcoding hints<br></span><span style=3D"color:rgb(12=
8,128,128);font-style:italic">        </span>t.addTranscodingHint(<wbr>SVGA=
bstractTranscoder.<span style=3D"color:rgb(102,14,122);font-weight:bold;fon=
t-style:italic">KEY_<wbr>HEIGHT</span>, <span style=3D"color:rgb(0,0,128);f=
ont-weight:bold">new </span>Float(<span style=3D"color:rgb(0,0,255)">600</s=
pan>));<br>        t.addTranscodingHint(<wbr>SVGAbstractTranscoder.<span st=
yle=3D"color:rgb(102,14,122);font-weight:bold;font-style:italic">KEY_<wbr>W=
IDTH</span>, <span style=3D"color:rgb(0,0,128);font-weight:bold">new </span=
>Float(<span style=3D"color:rgb(0,0,255)">600</span>));<br>        <span st=
yle=3D"color:rgb(128,128,128);font-style:italic">// convert and write outpu=
t<br></span><span style=3D"color:rgb(128,128,128);font-style:italic">      =
  </span>t.transcode(input, output);<br>        <span style=3D"color:rgb(12=
8,128,128);font-style:italic">// flush and close the stream then exit<br></=
span><span style=3D"color:rgb(128,128,128);font-style:italic">        </spa=
n>ostream.flush();<br>        ostream.close();<br>    }<br>}<br></pre></div=
><div><div>Compiled using Maven, this code repeatedly fails (using a variet=
y of SVG&#39;s)=C2=A0with the following exception.=C2=A0</div><div><br></di=
v><div>Exception in thread &quot;main&quot; org.apache.batik.transcoder.<wb=
r>TranscoderException: null</div><div>Enclosed Exception:</div><div>Could n=
ot write PNG file because no WriteAdapter is availble</div><div><span style=
=3D"white-space:pre-wrap">	</span>at org.apache.batik.transcoder.<wbr>image=
.ImageTranscoder.<wbr>transcode(ImageTranscoder.<wbr>java:132)</div><div><s=
pan style=3D"white-space:pre-wrap">	</span>at org.apache.batik.transcoder.<=
wbr>XMLAbstractTranscoder.<wbr>transcode(<wbr>XMLAbstractTranscoder.java:<w=
br>142)</div><div><span style=3D"white-space:pre-wrap">	</span>at org.apach=
e.batik.transcoder.<wbr>SVGAbstractTranscoder.<wbr>transcode(<wbr>SVGAbstra=
ctTranscoder.java:<wbr>156)</div><div><span style=3D"white-space:pre-wrap">=
	</span>at com.example.Main.main(Main.<wbr>java:26)</div><div><br></div><di=
v>After numerous Google searches, my theory is that the Maven repositories =
are missing a dependency, but my brain says &quot;blame yourself first,&quo=
t; which is why I am asking here.</div><div><br></div><div>Using the techni=
que for listing dependencies outlined at <a href=3D"https://grep.codeconsul=
t.ch/2010/07/08/list-all-your-maven-dependencies/" target=3D"_blank">https:=
//grep.codeconsult.ch/<wbr>2010/07/08/list-all-your-<wbr>maven-dependencies=
/</a>, I get the following list:<br></div><div><div>=C2=A0 =C2=A0 commons-i=
o:commons-io:jar:1.3.<wbr>1</div><div>=C2=A0 =C2=A0 commons-logging:commons=
-<wbr>logging:jar:1.0.4</div><div>=C2=A0 =C2=A0 junit:junit:jar:3.8.1</div>=
<div>=C2=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>anim:jar:1.9</div><div=
>=C2=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>awt-util:jar:1.9</div><div=
>=C2=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>bridge:jar:1.9</div><div>=
=C2=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>constants:jar:1.9</div><div=
>=C2=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>css:jar:1.9</div><div>=C2=
=A0 =C2=A0 org.apache.xmlgraphics:batik-<wbr>dom:jar:1.9</div><div>=C2=A0 =
=C2=A0 org.apache.xmlgraphics:batik-<wbr>ext:jar:1.9</div><div>=C2=A0 =C2=
=A0 org.apache.xmlgraphics:batik-<wbr>gvt:jar:1.9</div><div>=C2=A0 =C2=A0 o=
rg.apache.xmlgraphics:batik-<wbr>i18n:jar:1.9</div><div>=C2=A0 =C2=A0 org.a=
pache.xmlgraphics:batik-<wbr>parser:jar:1.9</div><div>=C2=A0 =C2=A0 org.apa=
che.xmlgraphics:batik-<wbr>script:jar:1.9</div><div>=C2=A0 =C2=A0 org.apach=
e.xmlgraphics:batik-<wbr>svg-dom:jar:1.9</div><div>=C2=A0 =C2=A0 org.apache=
.xmlgraphics:batik-<wbr>svggen:jar:1.9</div><div>=C2=A0 =C2=A0 org.apache.x=
mlgraphics:batik-<wbr>transcoder:jar:1.9</div><div>=C2=A0 =C2=A0 org.apache=
.xmlgraphics:batik-<wbr>util:jar:1.9</div><div>=C2=A0 =C2=A0 org.apache.xml=
graphics:batik-<wbr>xml:jar:1.9</div><div>=C2=A0 =C2=A0 org.apache.xmlgraph=
ics:<wbr>xmlgraphics-commons:jar:2.2</div><div>=C2=A0 =C2=A0 xalan:serializ=
er:jar:2.7.2</div><div>=C2=A0 =C2=A0 xalan:xalan:jar:2.7.2</div><div>=C2=A0=
 =C2=A0 xml-apis:xml-apis-ext:jar:1.3.<wbr>04</div><div>=C2=A0 =C2=A0 xml-a=
pis:xml-apis:jar:1.3.04</div></div><div><br></div><div>Does anyone see a pr=
oblem with my code?</div><div>-Al</div>-- <br><div class=3D"m_6462938449863=
425286gmail_signature">Please forgive typo&#39;s, equally likely to have be=
en typed on cell phone and to have been typed one-handed.<div><br></div></d=
iv>
</div></div>
</div></blockquote></div><br></div></div></div></div></div></blockquote></d=
iv><br><br clear=3D"all"><div><br></div>-- <br><div class=3D"gmail_signatur=
e" data-smartmail=3D"gmail_signature">Please forgive typo&#39;s, equally li=
kely to have been typed on cell phone and to have been typed one-handed.<di=
v><br></div></div>
</div>

--94eb2c1b048a19b8370554fd72bf--