Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save documentprocessing/9bd5a651ed3c958f318b7d0466a36a11 to your computer and use it in GitHub Desktop.
Save documentprocessing/9bd5a651ed3c958f318b7d0466a36a11 to your computer and use it in GitHub Desktop.
Add Textbox to Presentation with python-pptx
from pptx import Presentation
from pptx.util import Inches, Pt
presentation = Presentation()
blank_slide_layout = presentation.slide_layouts[6]
slide = presentation.slides.add_slide(blank_slide_layout)
#set the dimensions of the text box
left = top = width = height = Inches(1)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
tf.text = "Adding text to a textbox in slide"
p = tf.add_paragraph()
p.text = "A second paragraph in bold"
p.font.bold = True
p = tf.add_paragraph()
p.text = "A big third paragraph"
p.font.size = Pt(40)
presentation.save('textBox_in_presentation.pptx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment