1
votes

I'm parsing a PowerPoint file, some slides contains images. How do I detect if there are images in the slide?

I was checking within all shapes in the slide but I don't see any properties that could let me know if there is an image. Currently if I were to check the shape.AlternativeText I noticed they may contain the image name or path with extensions .png, .jpg, .gif etc. Which lets me know which shapes contains images but this doesn't apply to all images and is not consistent.

Anyone know of a way to detect for an image? A shape.hasImage would have been nice.

Thanks in advance.

2
Try to check for a fill type shape.Fill.FillType == FillFormatType.Picture. Also check here might be useful snippet.Renatas M.
I could not find "FillType" under Fill, I managed to find a Fill.textureName and TextureType. Both didnt help at all. Where did you see FillType?Eric
Ups sorry it's from different framework, not interop. You didn't mentioned what format of powerpoint presentation file you are trying to parse. If it is pptx then you can simply unzip file and parse slides as xmls where you will find <pic> tag.Renatas M.

2 Answers

2
votes

I know it's a late answer. But it might help some one else.

By using the below code you can find the no of images on each slide.

  for(int i=1;i<= Pres.Slides.Count;i++) 
      {

          Microsoft.Office.Interop.PowerPoint.Shapes shapes = Pres.Slides[i].Shapes;

            foreach(Microsoft.Office.Interop.PowerPoint.Shape shape in shapes)
            {
                if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                {
                   // set a counter or 2 dimensional  array to store how many shapes are in each slide.
                }

            }
     }
0
votes

Images can be placed just as images, they can be placed in a placeholder, or as picture fill to a shape or picture fill to a background or as a linked image. So to find all instances would be more work. This finds a photo placed on a slide, but not in a placeholder:

Sub FindPicture()
  Dim oSlide As Slide
  Dim oShape As Shape
  For Each oSlide In ActivePresentation.Slides
    For Each oShape In oSlide.Shapes
      If oShape.Type = msoPicture Then
        MsgBox oShape.Name
      End If
    Next oShape
  Next oSlide
End Sub