Create a new power point file and add slides and add images to each of these slides

Hi,

We are trying to evaluate Aspose.PDF to convert our pdf files to Microsoft PowerPoint file.

Basically, what we are trying to achieve is, instead of going with Aspose.PDF default conversion from pdf to pptx, will use the Aspose.PDF just to create the PowerPoint file and we will only extract the images from our reports and put them on the PowerPoint sildes that we have just created using Aspose.PDF. This is very much required to handle/avoid any conversion issues that we may get now or even in future.

So, Is it possible to do the below steps using Aspose.PDF assembly?

  1. Create a new power point file using Aspose.PDF assembly.
  2. Add slides as many as we need, as per our requirement.
  3. Add an image to each of these slides.
  4. Save the final PowerPoint file in some file location.

Please let us know, if this can be done. If yes, please give us the code/documentation site links to achieve the same.

Thanks in Advance.
Prathap

@PrathapSV

We are afraid that your requirements cannot be met using Aspose.PDF. Please note that Aspose.PDF is specialized to deal only with PDF documents and it cannot generate a PPT/PPTX file from scratch. In order to handle these files, we offer Aspose.Slides that is dedicated API to generate PowerPoint files. You can achieve your requirements by using it. In case you need more information, please let us know.

Yes, we can go with Aspose.Slides too, we just need to achieve what we mentioned earlier. Can you give us some links/documentation site, so that we can try this in our sample and see how it works?

Thanks,
Prathap

After some research, we found the documentation and now we are able to create a new power point template and adding the images using Aspose.Slides. So far it looks good, But we have below requirements which we are not able to figure out using the documentation sites. Please address them.
1. After we add the image to a slide, can we crop the top/bottom/left/right like we do using Microsoft interop.
>> this is ms interop code
=> slide.Shapes[1].PictureFormat.CropTop=customTopSetting.
Here is the msdn link which explains the CropTop purpose and how it works, Do we have a similar object in Aspose.Slides, If yes , please explain/give us the code on how to do the same?

>> this is using Aspose.Slides
asposeSlide.Shapes[1]. – Here we don’t know using which property we can crop the top.
Similarly, we need to crop bottom, left and right sections of the Added image/shape. Please let us know.

2. How can i add an Empty Slide using Presentation class. So far am using AddClone() function but not able to figure using AddEmptySlide()… Please let us know.
using (Presentation pres = new Presentation())
{
pres.Slides.AddClone(firstDefaultSlide);-- this is fine working,
pres.Slides.AddEmptySlide(new LayoutSlide()); this throws an compile time error saying LayoutSlide constructor does not takes 0 arguments, but not sure what to pass? Please help.

}

3. How do we create a PowerPoint using existing templates? we can do this in MS interop using their Presentation class like below,
presentation.ApplyTemplate(buttonEditTemplate.Text);.
But not sure, how to do the same using Aspose.Slides? Please help

Thanks in Advance.
Prathap

@PrathapSV,
Thank you for the issue description. I will answer you as soon as possible.

@PrathapSV,
Thank you for your patience.

Unfortunately, I have not found a related article. I requested a code example from our development team for you.

Each presentation slide in PowerPoint documents must be related to some layout slide. Usually, any presentation contains at least one layout slide. You can add the empty slide as shown below:

var layoutSlide = presentation.LayoutSlides[0];
presentation.Slides.AddEmptySlide(layoutSlide);

API Reference: ISlideCollection Interface

Could you describe your requirements in more detail with an example, please?

Could you describe your requirements in more detail with an example, please?

Microsoft PowerPoint has built-in Design Templates. So, i was asking that how can we create a new PPTX file using those any pre-defined existing design templates or any custom design templates that we have saved already.
Please let us know.

@PrathapSV,

You can use the next code snippet to crop images:

using (Presentation presentation = new Presentation())
{
    // Create new image object
    IPPImage newImage = presentation.Images.AddImage(Image.FromFile(imagePath));
    
    // Add PictureFrame to a Slide
    IPictureFrame picFrame = presentation.Slides[0].Shapes.AddPictureFrame(
        ShapeType.Rectangle, 100, 100, 420, 250, newImage);

    // Crop image (percentage values)
    picFrame.PictureFormat.CropLeft = 23.6f;
    picFrame.PictureFormat.CropRight = 21.5f;
    picFrame.PictureFormat.CropTop = 3;
    picFrame.PictureFormat.CropBottom = 31;

    // Save result
    presentation.Save(outPptxFile, SaveFormat.Pptx);
}

API Reference: PictureFillFormat Class

Please take a look at the next article: Presentation Theme. If the issue persists, please describe a case that you did not handle.