I’m attempting to implement the Batik library into my app in order to render the SVG taken from charts created with ExtJS into PNG images (e.g., view a chart, and then download an image of it). For the Batik integration, I’m following the example found here, and I’ve verified that it works. Here’s what my code looks like so far:
public void function makeImage( required string svg ) {
var pc = getPageContext();
pc.setFlushOutput( false );
var transcoder = createObject( “java”, “org.apache.batik.transcoder.image.PNGTranscoder” ).init();
// set content type for response
pc.getResponse().getResponse().setContentType( ‘image/*’ );
// set the right header to download the file from the browser
pc.getResponse().setHeader( “Content-Disposition”, “inline; filename=myfile.png” );
var inputStream = createObject( “java”, “java.io.StringBufferInputStream” ).init( svg );
var input = createObject( “java”, “org.apache.batik.transcoder.TranscoderInput” ).init( inputStream );
var outputStream = pc.getResponse().getResponse().getOutputStream();
var output = createObject( “java”, “org.apache.batik.transcoder.TranscoderOutput” ).init( outputStream );
transcoder.transcode(input, output);
outputStream.flush();
outputStream.close();
}
The problem I’m running into, however, is when I try to integrate this with ColdBox. If I make the method remote, and simply post the SVG to the method (e.g., handlers/mycfc.cfc?method=makeImage), it works exactly as I would expect it to (a png image is downloaded). However, if I call this method via a handler (or even put the guts of the method in a handler, for that matter), it downloads the file as before, but devoid of content (a blank image).
I assume the issue is with how the Batik library is handling the outputstream in the transcode() method, but don’t really know where to begin to debug this. I appreciate any insights/ideas that anyone might have regarding this.
Thanks!