GemBox Support Forum

How to measure textbox size, know when to split it?

I’m generating powerpoint slides with a mix of images and text. When the user enters large amounts of text I want to be able to split it into multiple slides.

How do I know when the text runs off the end of the slide, or how to measure the size of the text box after .AddParagraph().AddRun(…)?


Hi Mark,

You could set the TextBox to autofit its size based on its content and then call TextBox.Shape.FormatDrawing() to calculate that resizing.

In other words, something like this:

TextBox textBox = slide.Content.AddTextBox(...);
textBox.Format.AutoFit = TextAutoFit.ResizeShapeToFitText;

// Write some text...

double height = textBox.Shape.Layout.Height;

Then based on that calculated height and the slide’s height (minus the top position of the textbox) you could detect if the text is too large.

Or you could perhaps create a TextBox with a size that fully occupies the slide and then use TextAutoFit.ShrinkTextOnOverflow. That way you won’t need to slit the text into multiple slides.

I hope this helps.


Hi Mario,

Thanks for your reply. I tried the ‘shrinkTextOnOverflow’ but it doesn’t seem to work. What am I doing wrong here:

            var newslide = _ppt.Slides.AddNew(SlideLayoutType.Custom);
            textbox = newslide.Content.AddTextBox(x, y, w, h, LengthUnit.Centimeter);
            textbox.Format.AutoFit = TextAutoFit.ShrinkTextOnOverflow; 

            var papa = textbox.AddParagraph();

Hi Mark,

Which version of GemBox.Presentation are you using?
Can you please send us a small Visual Studio project that reproduces your issue so that we can investigate it?