Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Insert Image into the middle of an existing PowerPoint

I have an existing PowerPoint presentation with 20 slides. This presentation serves as an template with each slide having different backgrounds. I want to take this (existing) PowerPoint presentation, insert an image in slide number 4 (do nothing with the first 3) and save it as a new PowerPoint presentation.

This is what I have up until now. This code loads an existing presentation and saves it as a new one. Now I just need to know how to use this to insert an image to slide number 4 like described above.

Note: I am using normal Python.

from pptx import Presentation

def open_PowerPoint_Presentation(oldFileName, newFileName):
    prs = Presentation(oldFileName)
    #Here I guess I need to type something to complete the task.
    prs.save(newFileName)

open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx')
like image 862
Morganis Avatar asked Mar 07 '16 16:03

Morganis


1 Answers

I'm not really familiar with this module, but I looked at their quickstart

from pptx.util import Inches
from pptx import Presentation

def open_PowerPoint_Presentation(oldFileName, newFileName, img, left, top):
    prs = Presentation(oldFileName)
    slide = prs.slides[3]
    pic = slide.shapes.add_picture(img, left, top)
    prs.save(newFileName)

open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx',
                             'mypic.png', Inches(1), Inches(1))
like image 88
Moe Avatar answered Sep 18 '22 12:09

Moe