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.
 
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.
 
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 = "">
Thank you for any assistance with this.  I seem to have run out of things to try.
 
Kevin
KevLinDev - http://www.kevlindev.com

Reply via email to