CF8 and Batik (for SVG)

I just discovered that CF8 ships with a more complete Batik than CF7 did. Out of the box it's capable of transcoding SVG graphics to PNGs, which CF7's implementation wasn't capable of doing. With CF7 you had to move the partial Batik that came bundled and replace it with a full version to get transcoding to work, but no more. I'm not sure what CF8 uses it for, but CF7 appeared to use it for CFFORM stuff. Perhaps that's been extended and requires a full Batik, or maybe something else does. My initial thought was maybe the new Image libraries supported SVG, but that doesn't seem to be the case.

"Why SVG?", you ask? Because CFCHART is remarkably inflexible (and rather clumsy to boot) to the point that I wrote my own charting engine. It's hardly a CFCHART replacement, but far better suited to some of the charts that I need to produce. I chose SVG (several years ago, mind you) because it was widely supported and it's all text based, which makes generating it with CF a breeze. It also works as-is, or can be transcoded to a "normal" graphic (though you lose the vector base if you go to a raster format) for easier consumption.

Edit: Rob asked about the charts in the comments, so here's an example chart: capacity.png.  It doesn't really represent the full capabilities (area plots, multiple y-axes, etc.), but you get the idea.  The x-axis is labeled with age in days, with zero being midnight this morning.  If you've ever seen/used RRDTool (often paired with MRTG) the idea is similar, except that my database isn't round robin, it's historical, so I can change the time period on my dashboards and get charts back as far as I have data, if I want them.  Here's the same chart with data back to the beginning: capacity2.png.  As you can see, tracking of the 'imageCapacity' series started later (by about six months) than tracking 'totalImageCount'.  And no, those execution times (in the lower right) aren't representative – I grabbed these after a fresh restart so caches were empty.

17 responses to “CF8 and Batik (for SVG)”

  1. Rob Brooks-Bilson

    Hi Barny,

    Are you doing any chart types not supported by cfchart using your technique? Just curious…

  2. Rob Brooks-Bilson

    Fat fingers – make that Barney, not Barny!

  3. Mike

    That's the best reason I've heard so far to upgrade to CF8. I have an application that uses SVG to draw activity network diagrams in a browser using live data from a database (see http://www.teamtool.net/anp/anp.html). Previously I've had to persuade users either to use Firefox 2 to view the images (native SVG support) or use the Adobe SVG viewer plug-in for IE/FF1. But the plug-in doesn't work with Vista and this explains (sort of) why Adobe have no plans to upgrade it.

  4. John Jarrard

    Hi Barney,

    I'm entirely new to SVG (sadly, I know) and I was wondering if you could should me an example of coverting an SVG image to PNG using the built-in libraries of CF8.

    Thanks a milion.

  5. John Jarrard

    Thanks Barney – I ran your example code and I'm getting a java error…

    Object Instantiation Exception.

    An exception occurred when instantiating a Java object. The class must not be an interface or an abstract class. Error: org/apache/batik/dom/util/DocumentFactory.

    If you want to see the full error, here is a link:

    http://www.sterling-staging.com/svg.cfm

    I'm sorry to bug you, but you're the only help I have found online.

  6. John Jarrard

    @Barney – I found the problem. I was putting stuff in the CFFORMS folder inadvertently.

  7. John Jarrard

    Thanks so much Barney- its working like a charm now!

  8. John Jarrard

    Well I guess I thought I had it too soon… Is there some trick to linking in image files

    This code causes the renderer to return a blank white screen:

    Do i need to use a complete path?

  9. John Jarrard

    <image y="87.727219″ x="1″ height="189″ width="300″ xlink:href="{imgName}" />

  10. John Jarrard

    Hi Barney – the way I got the image to work was to use a full URI: file:///c:/inetpub/wwwroot/blah.jpg

    I'm still trying to figure out why the font render so ugly. If I render it huge (500%) – it seems to make it antialiased, but if I got 100% it look jagged and hideous.

  11. Zane Taylor

    Having no luck getting this code (including the CF8 example in the comments) to render on CF9, either with the built-in Batik libraries or ones that I install myself. The best I can get it to do is output an empty or unreadable PNG. Any thoughts? Anyone gotten Batik to behave on CF9?