Word Wrap

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  Re: Word Wrap

DynamicPDF CoreSuite for .NET (v9) Forum

 Mar 15 2019 5:23 AM
I've got a TextArea that has a certain height and width and a text that consists of two words that i need to word-wrap only whole words.
If the textarea only has room for 1 line then it is no problem, but for example if I have the text "HAPPY BIRTHDAY", the result would become:


Is there a way to FORCE the textarea not to break the BIRTHDAY-word this way?
 Mar 15 2019 12:37 PM
Posted by a ceTe Software moderator

The TextArea page element will break on words, or if the word is wider than the width of the TextArea, the word will be split into multiple lines. This is expected behavior with DynamicPDF Generator product.

If you are wanting to fit the text in a line then you can calculate the text width using Font or OpenTypeFont class. You can then use this calculated width on the TextArea so it can fit the text in a line. Below is the code sample:
        Document document = new Document();
        Page page = new Page();
        string text = "HAPPY BIRHTDAY";
        Font font = Font.Helvetica;
        float fontSize = 12;
        float textWidth = font.GetTextWidth(text, fontsize);
        TextArea area = new TextArea(text, 100, 100, textWidth, 400, font, fontSize);
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 1:03 AM.