batik


Javascript will not execute with PNGEncoder


I am trying to use the PNGEncoder class in batik to convert svg files to png format.
My code pretty much comes from the example given on the apache site.
public void writePng(String pngPath) throws Exception{
String parentPath=FileUtils.getParentPath(pngPath);
FileUtils.mkdirs(parentPath);
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD,new Boolean(true));
FileInputStream iStream=new FileInputStream(svgPath);
TranscoderInput input = new TranscoderInput(iStream);
OutputStream ostream = new FileOutputStream(pngPath);
TranscoderOutput output = new TranscoderOutput(ostream);
t.transcode(input, output);
ostream.flush();
ostream.close();
}
An snippet of the input svg with embedded javascript is below
<?xml version="1.0" encoding="UTF-8"?>
<svg contentScriptType="text/ecmascript" height="600" version="1.2" width="800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs/>
<script type="text/ecmascript" xlink:href="file:/D:/dev/svn/deathstar/xfltoalsxml/src/js/helper_functions.js"/>
<script type="text/ecmascript" xlink:href="file:/D:/dev/svn/deathstar/xfltoalsxml/src/js/textFlow.js"/>
<text id="defid_text_1" transform="matrix(1 0 0 1 269.9 57)"/>
<script type="text/ecmascript"><![CDATA[var textNode = document.getElementById('defid_text_1');
textNode.setAttributeNS(null,'x',0);
textNode.setAttributeNS(null,'y',0);
textNode.setAttributeNS(null,'font-size',18);
textNode.setAttributeNS(null,'font-family','ArialMT');
document.documentElement.appendChild(textNode);
textFlow('testdata abcd ',textNode,514.1,0,20,false);
]]></script>
</svg>
Whenever I try to run my writePng function I get the exception
ava.lang.Exception: Unknown language: text/ecmascript
at org.apache.batik.bridge.BridgeContext.getInterpreter(BridgeContext.java:575)
at org.apache.batik.bridge.BaseScriptingEnvironment.getInterpreter(BaseScriptingEnvironment.java:289)
at org.apache.batik.bridge.BaseScriptingEnvironment.loadScripts(BaseScriptingEnvironment.java:404)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:214)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
at com.amered.xfltojs.app.FrameToSvg.writePng(FrameToSvg.java:156)
at com.amered.xfltojs.app.DocData.generateImageData(DocData.java:172)
The files display properly when using squiggle.
I have checked everywhere I can think of and can find no explanation for why this is happening.
Hopefully someone has some suggestions.
I was struggling with the same exception. For some reason, this worked for me:
Instead of
TranscoderInput input = new TranscoderInput(new FileReader("myfile.svg"));
I use
String file = new File("myfile.svg").toURI().toString();
TranscoderInput input = new TranscoderInput(file);

Related Links

Is it possible to set the id for SVG elements drawn with SVGGraphics2D
What is the purpose of CSSEngine class in batik css parser
how to find package org.w3c.dom.svg?
Javascript will not execute with PNGEncoder

Categories

HOME
porting
linkedin
phpmyadmin
rdbms
pyqt
powerpoint
computer-science
project
siddhi
zerobrane
microsoft-dynamics-nav
dimensional-modeling
vuejs
git-extensions
visual-glitch
guzzle
inno-download-plugin
jquery-callback
fable-f#
ms-access-2003
intersystems-cache
comparable
testcomplete
nsurl
mockjax
weather
cognos-bi
installscript
engine.io
health-monitoring
unordered-map
portforwarding
sharp-snmp
http-request
file-sharing
apache-directory
launchctl
insight
seq
jtree
chromium-os
cudd
lrs
adafruit
hclust
dimension
freepbx
hadoop-partitioning
kiosk
ellucian-scribe
exim4
toran-proxy
iokit
fiware-monitoring
rubaxa-sortable
cgi-bin
batik
dulwich
cwrsync
telepat
bcache
ejb-2.x
lnk
paste
file-not-found
extjs2
android-audiorecord
high-resolution
eclipse-kepler
mysql-error-1044
cocoalibspotify-2.0
merb
node-blade
android-icons
http-status-code-410
thttpd
oracle-enterprise-linux
wiimote
infobright
jquery-address
hibernateexception
procedures
xcelsius
tmx
collectionviewsource
blender-2.49
burndowncharts
duplex
mathematical-notation
scrubyt
fail-fast-fail-early
wcf-proxy

Resources

Encrypt Message