SVG export uses incorrect image

I attach a simple powerpoint. It has two images on two slides with text to show which page.

I exported each slide as both SVG and PNG using the following code:

private static string SlideToSvg(ISlide slide)

{

var pres = new Presentation();

pres.Slides.RemoveAt(0);

pres.Slides.AddClone(slide); //optional, cloning to new presentation makes no difference

slide = pres.Slides[0];

var memoryStream = new MemoryStream();

slide.WriteAsSvg(memoryStream);

memoryStream.Seek(0, SeekOrigin.Begin);

return new StreamReader(memoryStream).ReadToEnd();

}

private static string SlideToPng(ISlide slide)

{

var pres = new Presentation();

pres.Slides.RemoveAt(0);

pres.Slides.AddClone(slide);

var memoryStream = new MemoryStream();

pres.Save(memoryStream, SaveFormat.Tiff);

memoryStream.Seek(0, SeekOrigin.Begin);

var bmp = Image.FromStream(memoryStream);

var mspng = new MemoryStream();

bmp.Save(mspng, ImageFormat.Png);

mspng.Seek(0, SeekOrigin.Begin);

var bs = new byte[mspng.Length];

mspng.Read(bs, 0, bs.Length);

return string.Format("data:image/{0};base64,{1}", "png", Convert.ToBase64String(bs));

}

I am formatting to present on a web page.

The result of the webpage is also attached, PNG first. You can see that while the text is fine on the SVG of Page2. The image is not correct.

Thanks

This is why it’s important and why I can't live with PNG, takes at least 3 times longer to generate PNGs via Tiffs for another simple document:

PNG took 9056ms

SVG took 1978ms


PNG took 6652ms

SVG took 1892ms


PNG took 1891ms

SVG took 630ms


PNG took 3312ms

SVG took 1023ms


Agh, the whole problem is down to showing two svgs on the same page.


The image ids are repeated

<symbol id="pic1"

Any idea what to do? Other than a search and replace?
Done it, you need to embed the SVGs in img tags:

private static string SlideToSvg(ISlide slide)
{
var memoryStream = new MemoryStream();
slide.WriteAsSvg(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return InlineImageStream(memoryStream, "svg+xml");
}

private static string InlineImageStream(Stream stream, string format)
{
var byteArray = StreamToByteArray(stream);
return string.Format("data:image/{0};base64,{1}", format, Convert.ToBase64String(byteArray));
}

Slide SVG

Hi,

Thanks for inquiring Aspose.Slides.

I have worked over the requirements shared by you and have generated the following sample code for your kind reference. I have seen that you have also been identify and resolve the issue on your end as well. For reference, you can also try using the following sample.

private static void SlideToSvg(ISlide slide,int Id)
{

var pres = new Presentation();

pres.Slides.RemoveAt(0);

pres.Slides.AddClone(slide); //optional, cloning to new presentation makes no difference

slide = pres.Slides[0];

var memoryStream = new MemoryStream();

slide.WriteAsSvg(memoryStream);

memoryStream.Position=0;
SaveStreamToFile(memoryStream, “D:\Aspose Data\Slides\Slide " + Id.ToString()+”.svg");

}

public static void SaveStreamToFile(Stream stream, string filename)
{
using (Stream destination = File.Create(filename))
Write(stream, destination);
}

//Typically I implement this Write method as a Stream extension method.
//The framework handles buffering.

public static void Write(Stream from, Stream to)
{
for (int a = from.ReadByte(); a != -1; a = from.ReadByte())
to.WriteByte((byte)a);
}

public static void testSVG()
{
Presentation pres = new Presentation(“D:\Aspose Data\TwoImages.pptx”);
int Id = 0;
foreach (ISlide slid in pres.Slides)
{
Id++;
SlideToSvg(slid, Id);
}
}

Many Thanks,