Create new presentation with images from another presentation RRS feed

  • Question

  • I have got the task that if i have one "power point file1" in desktop or any other location in computer, i need to create new "power point file2 " in c# and add all the images of the "power point file1" into "power point file2". i have been searching for three days but couldn't find the answer.

    Could you please guide me how to do this or send me possible solution with full code in c# . Thanks in advance.

    • Moved by CoolDadTx Friday, July 31, 2015 2:51 PM Office related
    Friday, July 31, 2015 3:19 AM


  • Here is a solution based on free presentation API. Download and import the dll file to your project,  then use following code extract images from presentation 1 and then insert every individual image to one single slide in presentation 2. The images display fully without resizing.
    //load sample file to ppt1
    Presentation ppt1 = new Presentation("sample.pptx",FileFormat.Pptx2010);
    //create ppt2
    Presentation ppt2 = new Presentation();
    for (int i = 0; i < ppt1.Images.Count; i++)
         //extract image from ppt1 and save to local folder
         Image image = ppt1.Images[i].Image;
         image.Save(string.Format("Images{0}.png", i));
         string ImageFile2 = String.Format(@"Images{0}.png", i);
         //add slide to ppt2
         if (ppt2.Slides.Count - 1 < i)
         //draw images to ppt2
         RectangleF rect = new RectangleF(50, 50, image.Width, image.Height);
         ppt2.Slides[i].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect);
         ppt2.Slides[i].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
    //save and preview the file
    ppt2.SaveToFile("result.pptx", FileFormat.Pptx2010);

    Friday, July 31, 2015 7:02 AM