Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Sat Feb 13, 2021 1:27 am

Hi,

I'm trying to add SVG image to Slide with this code.

string image_path = "c:\sample.svg";
IEmbedImage ashape = presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, image_path, new RectangleF(0, 0, 100, 200));

but it caused a error System.OutOfMemoryException.
The image size is not so large.

Could you give me a correcting to me? Or, Is it available to add SVG to Slide?

Thanks.

junichi.matsunoshita@fujixerox.co.jp
 
Posts: 12
Joined: Thu Jul 04, 2019 3:54 am

Mon Feb 15, 2021 10:54 am

Hello,

Thanks for your inquiry and sorry for the late reply as weekend.

Please refer to the following code to add the svg file to the slide.
Code: Select all
            Presentation pptPresentation = new Presentation();
            ISlide slide = pptPresentation.Slides[0];
            string image_path = @"J:\Source\ConsoleApp1\ConsoleApp1\bin\Debug\svgPic.svg";
            RectangleF rect = new RectangleF(50, 50, 300, 100);


            FileStream fileStream = File.Open(image_path, FileMode.Open);
            byte[] svgObj = new byte[fileStream.Length];
            fileStream.Read(svgObj, 0, svgObj.Length);

            IOleObject ole = slide.Shapes.AppendOleObject("svgPic.svg",svgObj, rect);

            pptPresentation.SaveToFile("addPic.pptx", FileFormat.Pptx2013);


If the code does not match your needs, please provide us with your input file and expect result file.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 493
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 16, 2021 11:39 am

Thank you for the reply.
I tried the code you gave in the reply, but it doesn't work as I expected. The shape added by the code just shows a text message "No Picture" in it and it isn't the image of the SVG file.
The SVG file I tried to add as a shape is a graphic like a icon or illustration, not a raster image. Are there any way to do that?
regards.

junichi.matsunoshita@fujixerox.co.jp
 
Posts: 12
Joined: Thu Jul 04, 2019 3:54 am

Wed Feb 17, 2021 7:12 am

Hello,

Thanks for your feedback.
Regarding the "No Picture" issue, it is because that when using our Spire.Presentation to add an ole object, you also need to use the following code to add a filling picture to the ole object, otherwise it will display the text "No Picture".
Code: Select all
            Image image = Image.FromFile(@"logo.png");
            IImageData oleImage = pptPresentation.Images.Append(image);
            //...
            ole.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;


We are sorry that our Spire.Presentation does not yet support adding SVG files as raster images directly to PPT. But we will consider adding a new feature to implement it. If there is any good news in the future, we will notify you.
Apologize for the inconvenience caused.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1252
Joined: Mon Oct 19, 2020 3:04 am

Wed Feb 17, 2021 10:28 am

Hi.
I think your advice means to add another picture file to the shape instead from the SVG and that is not the solution for my demand.
I wish you will add the function to add SVG to slide for future version of Spire.Presentation.
thanks.

junichi.matsunoshita@fujixerox.co.jp
 
Posts: 12
Joined: Thu Jul 04, 2019 3:54 am

Thu Feb 18, 2021 2:48 am

Hello,

Thanks for your response.

Okay, we will add the function to directly add SVG files to PPT. If it is implemented in the future, we will let you know.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1252
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Presentation