2

I am currently working on a project aiming to create a PowerPoint thanks Python pptx. However I am trying to set an image as the background of the slide and I can’t seem to find the solution in the docs of Python pptx. Is it possible to set an image as background if so can someone help me ? If it is not does anyone know another solution using python ?

Thank you

import os
import fnmatch
from pptx import Presentation

#Create presentation and setting layout as blank (6)
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]

#Find number of slides to create
#First Method = Count number of images in screenshot files (change path depending on the user)
nbSlide = len(fnmatch.filter(os.listdir("mypath"), '*.jpeg'))

#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
    slide = prs.slides.add_slide(blank_slide_layout)
    #change background with an image of the slide …
    background=slide.background

#Final step = Creation and saving of pptx
prs.save('test.pptx')

1 Answers1

0

Is it possible to set an image as background ... ?

So far with python-pptx there is no direct way to insert image as background of an slide

If it is not does anyone know another solution using python ?

You could insert picture of interest into given slide on the regular basis, considering proper width/height parameters:

#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
    slide = prs.slides.add_slide(blank_slide_layout)
    #change background with an image of the slide …
    left = top = 0
    pic = slide.shapes.add_picture('/your_file.jpeg', left-0.1*prs.slide_width, top, height = prs.slide_height)
Oskar_U
  • 472
  • 4
  • 13