Auto for text on all textboxes

I am trying to update an existing document, adding text and graphs etc. However the text added can sometimes be quite long and overflow the page. so I need to loop through all slides and set the textboxes to be ‘autofit’

Howevere I’m unsure how to select only the textboxes

 foreach (var drawing in slide.Content.Drawings)
 {
     if (drawing is GemBox.Presentation.Shape shape)
     {
         if (shape.Text != null && !string.IsNullOrEmpty(shape.Text.ToString()) && shape.Text.ToString().Length > 0)
         {
             //doesn't work as its a shape not a textbox
             //shape.Format.AutoFit = GemBox.Presentation.TextAutoFit.ShrinkTextOnOverflow;

             shape.FormatDrawing();
         }
     }
 }

I am assuming its something like this but I can’t find the corrent syntax to find only textboxes.

Hi Joseph,

You need to use shape.Text.Format.AutoFit, for example:

foreach (var drawing in slide.Content.Drawings.All())
    if (drawing is Shape shape && shape.Text != null && !string.IsNullOrEmpty(shape.TextContent.ToString().TrimEnd()))
    {
        shape.Text.Format.AutoFit = GemBox.Presentation.TextAutoFit.ShrinkTextOnOverflow;
        shape.FormatDrawing();
    }

Does this solve your issue?

Regards,
Mario

I have attached a copy of the slide, as you can see it reduces the text to a size so small its unreadable even though it has plenty of whitespace underneath to expand into.

If I go to the settings in powerpoint and select the ‘shrink text to fit’ option it redues it enough to fit but its still readable.

here is a google drive link to the powerpoint Loading Google Slides

What version of GemBox.Presentation are you using?

I’m unable to reproduce this issue with the current latest version, can you please try again with it:

I’m currently using version 25.0.1420, I tried upgrading but my key is no longer valid, I assume to use the latest version I would need to purchase a new key? or is it possible to get a trial key to see if it fixes the issue.

Tested it with the lates version and it does seem to have fixed it, would it be possible to get a 30 day trial key so I can test it with out the trial text changes?

Hi Joseph,

I’ll send you a time-limited serial key.

Regards,
Mario