Search code examples
powerpointopenxmlpython-pptx

Putting A Box Round A Text Run - For Powerpoint


I would like to put a box around a text run in Powerpoint. Specifically a border. For example, a word might have a light green background (done by highlighting) and a thin black border line.

I've solved the "highlighting with a light green background" part - using a RGB value. That's fine.

Is it feasible to draw a box boundary line round a run?

I'm specifically looking for an example XML fragment - if this is feasible. (I use python-pptx and augment it with my own XML confection.)


Solution

  • I don't believe so Martin. A run is not a shape, so it doesn't have a border that can be turned on or off or given a color. You can find an excerpt of the XML schema showing what elements and attributes can go in a run-properties element (<w:rPr>) here: https://python-pptx.readthedocs.io/en/latest/dev/analysis/txt-font-underline.html?highlight=CT_TextCharacterProperties#related-schema-definitions

    It can have a ln child element, which corresponds to a pptx.dml.line.LineFormat object, but that's going to set the format of the font "outline", like if you want the interior of each letter to be a different color than its outline. You could create a LineFormat object for a run if you wanted to experiment with it using line = LineFormat(run.font._element).

    The other test would be whether you can do such a thing from the PowerPoint application UI. If you can't do it on Windows PowerPoint, it's very unusual that you can do it from the XML (although there are a few cases). Mac PowerPoint can't do everything Windows PowerPoint can, so that's less of a compelling "proof".