0

There's something which I do not understand going on between getting the SVG code from the SQL table and passing it into Batik to transcode it (displaying the PNG).

If I run the CF code below I get an error: The image cannot be displayed because it contains errors. This is the only error any of this produces.

I also tested the value from the table with isXML() which returns true.

But if I:

  1. un-comment Section 1,
  2. COPY the SVG code produced by the CFDUMP,
  3. paste that SVG code back into the CFSET in Section 2,
  4. and re-comment-out comment section 1

THEN the PNG displays in the browser as expected. The process of displaying the SVG code in CFDUMP and then manually pasting it into the code to use it somehow (mysteriously) alters it so it works...

I've tried all sorts of variations. It seems like ColdFusion is doing something I don't understand when it displays the SVG code in CFDUMP (OR possibly is it some sort of charset issue from SQL?).

Anyone have any ideas what this might be? I'm stymied.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<CFQUERY NAME="getSketch">
  SELECT sketch_svg AS svg
  FROM sketch
  WHERE  ordID = 1
</CFQUERY>
<cfset svg = Replace(getSketch.svg,'&quot;','','all')>

<!--- Commented-out Section 1
<cfset svg = Replace(svg,"'","''",'all')>
<cfset svg = Replace(svg,"##","####",'all')>
<CFDUMP var="#svg#" abort>
--->

<!--- Commented-out Section 2
<cfset svg = '[Manually paste SVG code from CFDUMP here...]'>
 --->

<!--- The following takes the svg code and displays it as a PNG in the browser - This works fine if the SVG code is okay...)  --->
<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);
  output.close();
  outputStream.close();
</cfscript>
Andrea
  • 11,801
  • 17
  • 65
  • 72
MikeW
  • 369
  • 1
  • 3
  • 8
  • `cfdump` definitely manipulates the data so that it can be displayed in the browser. Try this, uncomment your `cfdump` code and run it. Then open up your browser's 'view source' option. Now look at the cfdump'ed output in the source to see what that string looks like. Maybe it will shed some light on the formatting that `cfdump` is doing and you can do something similar in your code. – Miguel-F Nov 01 '12 at 12:28
  • Since you are dealing with XML another thing might be to try the `xmlformat()` function. [See the documentation on that here](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e62.html) – Miguel-F Nov 01 '12 at 12:31
  • @Miguel-F It escaped-out all the XML, example; `<svg preserveAspectRatio="xMinYMin" viewBox="130 98 140 105"` but that then gets displayed in the browser as the regular characters so when I copy and past it back in... I begin to wonder if this has something to do with saving to and/or retrieving from the SQL table... – MikeW Nov 02 '12 at 05:07
  • @Miguel - Next I'm going to try transcoding SVG straight from the DOM. If that works then perhaps it strictly something that saving into and restoring out of SQL is doing. – MikeW Nov 02 '12 at 05:21
  • I might have missed it but did you try copying the text from the browser's source code without using the `xmlformat()` option? What did that string look like since it seems to work when you manually paste it in your code. – Miguel-F Nov 02 '12 at 12:25
  • I'd like to throw this question out and start over... After much testing I've gotten closer to the problem which seems to have to do with jQuery Ajax and a SQL update rather than what I thought it was... – MikeW Nov 03 '12 at 19:04
  • possible duplicate of [jQuery ajax seems to alter SVG data sent to coldfusion server](http://stackoverflow.com/questions/13216397/jquery-ajax-seems-to-alter-svg-data-sent-to-coldfusion-server) – Leigh Nov 04 '12 at 21:22
  • It doesn't look related to that other question to me. – Adam Cameron Mar 29 '13 at 02:14
  • I've continued working on and refining this issue and have narrowed the problem down. I have posted another question #13216574 which really seems to get to the bottom of the question. As it so often happens it wasn't what I thought it was... – MikeW Nov 03 '12 at 19:59

0 Answers0