Hi,
I'm currently using a Tomcat servlet to transform an uploaded SVG document. Once the document is transformed, I generate a PNG preview with Batik and then insert that image into the transformed document as a base64 encoding image; however, my preview image is always blank.
I've done some searches and see that I should do some sanity tests like making
sure that the root element is an svg element and that it is in the SVG namespace. All of that checks out OK. As a test, I have been able to generate the preview of the non-transformed document. This seems to be specific to SVG documents that are transformed with Xalan. As another test I wrote the transformed file to a temporary file and then tried to rasterize that file...same result...blank image.
It is very strange because I can view the temporary file in Squiggle (and ASV3).
It certainly looks like a namespace problem, but everything seems to be fine.
The problem almost certainly has to do with the base url of the document. If you transcode from a stream it doesn't have one (unless you provide one to the input stream). You can also provide an xml:base attribute to set the base to resolve URL's against.
Are you sure you aren't getting error messages of any sort?
FWIW, I am serializing the transformed and then reparsing to create a new SVG document. My understanding from the code in Squiggle is that I have to do this.
Pretty much, what you really need is for Xalan to create the output document using our DOM implementation. You might find it faster to deep clone the DOM into our implementation rather than serialize and parse.
Let's see I'm running WinXP, Java 1.4.1_04, Tomcat 4.1, Batik 1.5, and Xalan 2.5.
A snippet from the transform code looks like:
// load stylesheet
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(
new StreamSource(path)
);
// apply transform
StringWriter sw = new StringWriter();
transformer.transform(
new StreamSource(source),
new StreamResult(sw)
);
sw.flush();
sw.close();
// build and return SVGDocument
return new SAXSVGDocumentFactory(
XMLResourceDescriptor.getXMLParserClassName()
).createSVGDocument(
"http://localhost:8080/uploadTest/",
new StringReader(sw.toString())
);
A snippet from the preview insertion looks like:
PNGTranscoder t = new PNGTranscoder();
TranscoderInput input = new TranscoderInput(svgDocument);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
TranscoderOutput output = new TranscoderOutput(ostream);
// setup transcoder hints
t.addTranscodingHint(PNGTranscoder.KEY_INDEXED, new Integer(256));
t.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);
t.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(100));
t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, new Float(100));
// transcode
t.transcode(input, output);
// convert result to base64 encoding
ostream.close();
Base64 b64 = new Base64();
String data = b64.encode(ostream.toByteArray());
Thank you for any assistance with this. I seem to have run out of things to try.
Kevin KevLinDev - http://www.kevlindev.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]