We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Simple Aspose save as PPT not working

Hi I do have a very simple case of adding images and saving as PPT to the template. I am doing this in .NET MVC. Following is the controller

        public ActionResult GetPPTFile()
{
        <span style="color:#2b91af;">Presentation</span> presentation = <span style="color:blue;">new</span> <span style="color:#2b91af;">Presentation</span>(Server.MapPath(<span style="color:#a31515;">@"..\BaseTemplate.ppt"</span>));
        presentation.Pictures.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">Picture</span>(presentation, Server.MapPath(<span style="color:#a31515;">@"..\Images\orderedList0.png"</span>)));
        presentation.Pictures.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">Picture</span>(presentation, Server.MapPath(<span style="color:#a31515;">@"..\Images\orderedList0.png"</span>)));
        presentation.Pictures.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">Picture</span>(presentation, Server.MapPath(<span style="color:#a31515;">@"..\Images\orderedList0.png"</span>)));
        presentation.Pictures.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">Picture</span>(presentation, Server.MapPath(<span style="color:#a31515;">@"..\Images\orderedList0.png"</span>)));

        <span style="color:#2b91af;">MemoryStream</span> memoryStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
        presentation.Save(memoryStream,<span style="color:#2b91af;">SaveFormat</span>.Ppt);

        <span style="color:blue;">return</span> File(<span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(memoryStream.GetBuffer(), <span style="color:blue;">false</span>), <span style="color:#a31515;">"application/x-mspowerpoint"</span>, <span style="color:#a31515;">"Chart1.ppt"</span>);
    }<br><br>My view is having the following code <br><br><span style="background:yellow;">@</span>Html.ActionLink(<span style="color:#a31515;">"PPT File"</span>, <span style="color:#a31515;">"GetPPTFile"</span>, <span style="color:#a31515;">"Home"</span>, <span style="color:blue;">null</span>, <span style="color:blue;">new</span> { id = <span style="color:#a31515;">"download"</span>})



File is getting created but none of my pictures are seen. Any ideas ?


Hi Ajay,


Thanks for your interest in Aspose.Slides.

I have observed the sample code shared by you and like to share that you are only adding the images in presentation picture collection and not in any shapes to make them visible. Please visit this documentation link for your kind reference.

Many Thanks,

Mudassir,

Thank you very much for the reply. Now I am able to see my slide in the file. But when I open the file, I always get an dialog saying that file is corrupted would you like to repair it. Is this common or am I doing something wrong. I have following code

var pres = new PresentationEx();
SlidesEx slds = pres.Slides;
int slideIndex = 0;
slds.AddEmptySlide(pres.LayoutSlides[slideIndex]);
SlideEx sld = pres.Slides[slideIndex];
ImageEx imgx = pres.Images.AddImage(stream);
sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 50, 150, imgx.Width, imgx.Height, imgx);

var memo = new MemoryStream();
pres.Save(memo, SaveFormat.Pptx);


Hi Ajay,


I have observed the sample code shared and there seems to be no issue in it. Can you please share the generated presentation along with PowerPoint version where you have obtained the issue. Please also share the sample image that you are adding on your end. I will try to reproduce the same on my end. I hope you will be using Aspose.Slides for .NET 7.1.0 on your end.

Many Thanks,

For sample I am using a graph as my image:
http://cricages.com/wp-content/uploads/bar-graph.gif
Also I am using Power Point 2010. I have attached the generated .PPTX for your reference and using Aspose.Slides for .NET File version 4.2.0.0

Also when you click on the repair you can see the image is not in the center of the image, can you tell me how to achieve this.

Thank you

Hi Ajay,


Thanks for sharing the gif image. I have used the following sample code for adding the gif image to slide using Aspose.Slides for .NET 7.1.0 and have not been able to reproduce the issue on my end. For your kind reference, I have attached the generated presentation as well. Please try using the specified version on your end and hopefully things will work.

String path = @“C:\Users\Mudassir\Downloads”;
PresentationEx pres = new PresentationEx();
SlidesEx slds = pres.Slides;
int slideIndex = 0;
slds.AddEmptySlide(pres.LayoutSlides[slideIndex]);
SlideEx sld = pres.Slides[slideIndex];
FileStream stream = File.OpenRead(path + “bar-graph.gif”);
stream.Position = 0;

ImageEx imgx = pres.Images.AddImage(stream);
sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 50, 150, imgx.Width, imgx.Height, imgx);

pres.Save(path+“AddedGif.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);


Many Thanks,

Mudassir

I am able to open the attached file without any warning. I got a trial license for .NET 7.1.0 and tries the same process. Still I am getting same repair dialog when I save the PPT file.

I will try again. Also could you please tell me how to center the image in the slide.

Hi Ajay,


I have attached the sample project for your kind reference that I have developed using Aspose.Slides for .NET 7.1.0 on my end. Secondly, I have also added the logic for setting the image to center of slide as well. You can please use that as reference and can change that accordingly as per your needs.

Many Thanks,