scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.26k stars 499 forks source link

New text box text starts on line 2 with first line being blank... cannot solve. #918

Closed beauxapps closed 8 months ago

beauxapps commented 8 months ago

Help!

Love the package. No issues except the following one -- creating a text frame in a shape with the following:

       text = text_small
       text_frame = box.text_frame
       text_frame.paragraphs[0].space_after = Pt(0)
       p = text_frame.add_paragraph()
       p.clear()
       p.text = "TODO"
       p.font.size = Pt(12)
       p.alignment = 1  # Center alignment
       p.font.name = font_name
       p.font.bold = True
       p.alignment = PP_ALIGN.CENTER

However, no matter what I try the text ends up on line 2 of the text frame with an empty line above it.

Ideas?

The following is what i've tried so far that has not helped...

       text_frame.paragraphs[0].space_after = Pt(0)
       p = text_frame.add_paragraph()
       p.clear()

Here's the generated ppt

image image

scanny commented 8 months ago

A text frame is born with a single empty paragraph. So you put your text there then only add a new paragraph if you need another.

beauxapps commented 8 months ago

Fantastic! Thanks!