Free Support Forum - aspose.com

Save SVGDocument to stream

I would like to save an SVGDocument to a stream rather than a file. This is for sending an svg modified at runtime to the browser. Is there a way to do this?

If I render the document into an image format (png for example), I can output to a stream directly:

        ImageRenderingOptions imageOptions = new ImageRenderingOptions(ImageFormat.Png);
        MemoryStream ms = new MemoryStream();
        using (ImageDevice device = new ImageDevice(imageOptions, ms))
        {
            document.RenderTo(device);
        }
        return ms;

But to save the svg document itself, I need to save to a temporary file and then read the file into a stream, like this. This is a noticeable performance hit when serving multiple svg images to a web page.

        // assume myStream contains my SVG document to be modified at runtime
        SVGDocument document = new SVGDocument(myStream, "")

        // do things to the document here, then...

        document.Save(someTemporaryFilePath);
        // return a stream
        return System.IO.File.OpenRead(someTemporaryFilePath);

The Save method does not have an overload to save to a stream.

Any advise would be welcome.

@GPTW_Jim

We need to investigate the feasibility of support to save the output to stream. For the purpose, we have logged an enhancement request as SVG-92 in our issue tracking system. We will further investigate possibility of this feature and let you know as soon as it is available. Please be patient and spare us some time.

We apologize for the inconvenience.