1

I have one pptx file which contain 10 image(jpg). Now i want to remove some images from pptx. I have the code through which i can extract all the images present in pptx. But at same time i want to delete 2-3 images from pptx.

Can anyone help me to get the logic or any libarary to delete image in pptx using python.

Anuj
  • 119
  • 8

2 Answers2

1

If you use python-pptx library you can remove certain images with the following:

from pptx import Presentation

pres = Presentation("test.pptx") # name of your pptx
slide = pres.slides[0] # or whatever slide your pictures on
pic  = slide.shapes[0] # select the shape holding your picture and you want to remove

pic = pic._element
pic.getparent().remove(pic) # delete the shape with the picture

pres.save("test.pptx") # save changes

botivegh
  • 370
  • 2
  • 13
0

You can delete all images in a presentation using python-pptx

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE

prs = Presentation("Presentation1.pptx") # name of your pptx
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
            pic = shape._element
            pic.getparent().remove(pic)
prs.save("test.pptx") # save changes
Naren Babu R
  • 453
  • 2
  • 9
  • 33