0

I have to place text in a given rectangle. Text can wrap and can be resized. Phrase can be split at "blank", but no word can be broken in parts.

I don't know how to do it. I have tried with FitText function and MOSTLY works, but, for example, if I have a very long word and a tall and thin rectangle (like 200 px x 1000 px) the word is splitted (filling the height of the rectangle).

Any ideas?

p.s.: I work with version 4

EDIT: The proposed solution did not work, because still split words: for example "averylongword" became "avery \n long \n word", instead my need is to have "averylongword" in one line, obvsiusly reducing fontsize.

Just to make an example I have a phrase like "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at viverra est. Donec a sagittis leo, et vestibulum ipsum. In nec efficitur tellus." and I have to make it fit a rectangle of (for example) 400 px x 200 px, wrapping only on spaces. The actual use of the "FitText" function works with phrase with a lot of words like the one above, but do not work as desired for 2-3 word phrase (split words in the middle)

In shorts I need a function that give to me correct fontsize needed to fill a rectangle with a phrase without word splitting, immagine a FitText function but with the option "no word split", is this possible?

Luca
  • 45
  • 6
  • If the word is wider than the rectangle what do you think should happen? – Paulo Soares Mar 09 '15 at 22:36
  • well, for my needs the font size should be decreased down until the word fit. I know that this is not common scenario in wordprocessing, but I need to write labels and tags and splitting the word is not an option. btw, thank you for your time. – Luca Mar 10 '15 at 08:18
  • Possible duplicate of [How to fit a String inside a rectangle?](http://stackoverflow.com/questions/13526043/how-to-fit-a-string-inside-a-rectangle). p.s.: I don't like your p.s. Read the answer to the final question in the legal section of [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html) for more info. – Bruno Lowagie Mar 11 '15 at 14:05

0 Answers0