PDF - Fit text into rectangle

Hi
I would like add (multiline) text to page in specific location (rectangle) and check if it fits into it.
If not, I would like to change font size and try it again. How can I know whether text fits into rectangle or not?

I tried to create new paragraph with specified rectangle and wrapping by words. Then I tried add text fragmen into it, but I don’t know how can I check if it fits or not.

@senny90

Can you please share the sample code snippet that you have tried so far? We will test and modify it at our end to achieve your requirements and will share with you.