This SVN rendering hack only works on ColdFusion, not Railo. The general idea still holds, but the response handling is simpler and you have to supply Batik yourself.
svg_demo.cfm<cfoutput> <h1>ColdFusion Only</h1> <p>This SVN rendering hack only works on ColdFusion, not Railo. The general idea still holds, but the response handling is simpler and you have to supply Batik yourself. </p> <!--- <img src="svg_demo_img.cfm" /> ---> <h2><code>svg_demo.cfm</code></h2> <pre>#htmlEditFormat(fileRead(getCurrentTemplatePath()))# </pre> <h2><code>svg_demo_img.cfm</code></h2> <pre>#htmlEditFormat(fileRead(replace(getCurrentTemplatePath(), "svg_demo", "svg_demo_img")))# </pre> </cfoutput>
svg_demo_img.cfm<!--- doesn't work on Railo, so redirect to info page --->
<cflocation url="svg_demo.cfm" statusCode="303" addToken="false" />
<cfsavecontent variable="svg">
<cfoutput>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width='300px' height='300px'>
<title>Small SVG example</title>
<circle cx='120' cy='150' r='60' style='fill: gold;'>
<animate attributeName='r' from='2' to='80' begin='0'
dur='3' repeatCount='indefinite' /></circle>
<polyline points='120 30, 25 150, 290 150'
stroke-width='4' stroke='brown' style='fill: none;' />
<polygon points='210 100, 210 200, 270 150'
style='fill: lawngreen;' />
<text x='60' y='250' fill='blue'>Hello, World!</text>
</svg>
</cfoutput>
</cfsavecontent>
<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
response.setContentType("image/png");
transcoder = createObject("java", "org.apache.batik.transcoder.image.PNGTranscoder").init();
inputStream = createObject("java", "java.io.StringBufferInputStream").init(svg);
input = createObject("java", "org.apache.batik.transcoder.TranscoderInput").init(inputStream);
outputStream = response.getOutputStream();
output = createObject("java", "org.apache.batik.transcoder.TranscoderOutput").init(outputStream);
transcoder.transcode(input, output);
outputStream.close();
</cfscript>