Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Mar 11, 2019 6:24 am

Hi, I am trying to add a shape to a new presentation and delete it from the old presentation however the AddShape method does not seem to be working, it is not passing the shape I have copied from the source to the target presentation. Removing the shape is working though.
Below is the code I used for this:

Code: Select all
public void CopyShape()
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(FILEPATH);

            var shapeSlides = new List<ShapeSlides>();
            int i = 0;

            foreach (ISlide slide in ppt.Slides)
            {
                var shapes = slide.Shapes.ToArray();

                if (shapes.Any())
                {

                    var shapeSlide =
                        new ShapeSlides
                        {
                            SlideIndex = i
                        };

                    shapes.ToList().ForEach(t => { shapeSlide.Shapes.Add(t); });

                    shapeSlides.Add(shapeSlide);
                }

                i++;
            }

            Presentation pptout = new Presentation();

            foreach (var shapeSlide in shapeSlides)
            {
                var slide = pptout.Slides.Append();

                foreach (IShape shape in shapeSlide.Shapes)
                {
                    if (shape != null)
                    {
                        slide.Shapes.AddShape((Shape)shape);
                    }
                    ppt.Slides[shapeSlide.SlideIndex].Shapes.Remove(shape);
                }
            }

            pptout.SaveToFile(FILEPATHOUT2, FileFormat.Auto);
            ppt.SaveToFile(FILEPATHOUT, FileFormat.Auto);
        }


The ShapeSlides class
Code: Select all
public class ShapeSlides
    {
        public int SlideIndex { get; set; }
        public List<IShape> Shapes { get; set; } = new List<IShape>();
    }


Thanks!

robertodr
 
Posts: 2
Joined: Fri Mar 01, 2019 4:23 am

Mon Mar 11, 2019 8:28 am

Hello,

Thank you for contacting us.
I tested your scenario with our latest Spire.Presentation Pack Hotfix Version:4.3.3, it could add shapes successfully. If you were using an old version, I suggest that you download our latest version to try again. If your issue still occurs after trying, to help us look into your issue quickly and accurately, please provide your input PPT file as well as output PPT files. You could send them to us via email ([email protected]). Besides, please kindly note that there is a default slide when creating a new Presentation(), you can use the following code snippet to remove it.
Code: Select all
......
      Presentation pptout = new Presentation();
      pptout.Slides.RemoveAt(0);
      foreach (var shapeSlide in shapeSlides)
......

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Tue Mar 12, 2019 8:56 am

Thanks Lisa I will try out your suggestion.
I will send out an email also with the attached input presentations as well.

robertodr
 
Posts: 2
Joined: Fri Mar 01, 2019 4:23 am

Tue Mar 12, 2019 9:07 am

Hello,

Ok, I am looking forward to your further reply. Hope everything goes well.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Presentation

cron