Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Text value change on Powerpoint by using OpenXml doesn't fit

I use OpenXml for creating custom powerpoint presentation in this way: I put a keyword on the presentation, I found it during process with OpenXml and change the text value. Everything work fine but the fit option doesn't work at first. The text box has options "Autofit: Shrink text on overflow; Wrap text in shape: On" After my process, the new text appear on the right place but the autofit is not done, I need to click on the text box and make a input for see the autofit work. I think that PowerPoint only check option after a modification.

What I want is the autofit option is called at the end of the process. Can anyone help me?

I hope you understand what I want to do.

Thanks.

like image 386
Arnaud Bessems Avatar asked Oct 03 '12 10:10

Arnaud Bessems


1 Answers

It's not possible using just OpenXML. The <a:normAutofit/> tag is used by a client application, such as PowerPoint, to render the text larger or smaller, as needed. OpenXML doesn't actually render anything, so until the client does, it will just read the text as if it is not auto-fitted.

There are a few options to think of to control this - none of them great however. One would be to use VSTO or VBA in PowerPoint to check all shapes on PPTX open and if they have a AutoFit tag, to re-render them. A second way would be to do all the font measurements yourself based on the shape's width & height and then set the font scale to the appropriate percentage. Another would be to make a textbox large enough to fit the largest amount of text you will ever insert and then turn autofit off.

Sorry this doesn't really help you immediately. I've done tons of research on this particular subject and it's all bad news.

like image 52
Todd Main Avatar answered Nov 16 '22 10:11

Todd Main