Hi,
I want to display the first part of a FormattedTextArea in a line followed by "..." in case the text is longer that the space in which I want to display it. How can I do this?
FormattedTextArea add ... at the end of first line
Re: FormattedTextArea add ... at the end of first line
Support · Jan 31, 2007Hello,
The best way to do this is take two FormattedTextAreas one for displaying the text and the other to display the "...". You can find out the width required for the text by using the GetTextWidth method of the Font class which takes the text and the font size as parameters. Check whether the text width is more than the FormattedTextArea width or not, if it is more then make the FormattedTextArea having "..." visible.
If this is what you are expecting then please let us know and explain a bit more about what you are expecting and if possible please provide with an example.
Thanks,
ceTe Software Support Team.
Re: FormattedTextArea add ... at the end of first line
Forum member · Jan 31, 2007Hello,
Thank you for your quick reply. Here's my initial attempt to implement the "..." requirement:
FormattedTextArea formattedTextArea = new FormattedTextArea( text, x1, y1, x2-10, y2, style );
page.Elements.Add( formattedTextArea );
if(formattedTextArea.HasOverflowText())
{
Label label = new Label("...",x1+x2-10,y1,15,15, Font.Helvetica,fontSize,new WebColor(eventStyle.foreColor));
page.Elements.Add(label);
}
There are a few things that aren't ok with the approach above:
1. I have to make the width of the area where the text is displayed smaller (x2-10) to leave space for the "..." label so overall the text in the cells where the text overflows is no longer centered as the text where there is no overflow.
2. When the formatted text is truncated there is no way to control the amount of white space between the text an the "..." so as a result the text looks ok sometimes and quite odd other times (way too much white space between the text and the ...).
I'm not sure I understand if the approach you suggested solves any of the issues above:
if(formattedTextArea.HasOverflowText())
{
Font font = new Helvetica( Encoder.CentralEurope );
float width = font.GetTextWidth(formattedTextArea.Text, fontSize);
Label label = new Label("...",x1+width,y1,15,15, Font.Helvetica,fontSize,new WebColor(eventStyle.foreColor));
page.Elements.Add(label);
}
Isn't GetTextWidth returning the width of the entire formattedTextArea instead of the width of the text that is displayed after is truncated (which is actually needed) ?
Thank you.
Re: FormattedTextArea add ... at the end of first line
Support · Jan 31, 2007Hello,
The width for the original and overflow FormattedTextArea will be same and they will appear exactly same on all pages based on the width you set at the time of creating the FormattedTextArea. I am not exaclty sure what you meant by "text in the cells where the text overflows is no longer centered as the text where there is no overflow."
Currently we can not think of any way to get access to the last line of text of the FormattedTextArea on the page so that we can directly add the ... to the end of that string. This will result in variable amount of white space between the text and the dots using the method you described. I will continue looking into it and see if there is a way around this.
Yes, the GetTextWidth() method will return the width of the FormattedTextArea in this case. The method is useful when the text is going to be only one line (e.g. Labels), so that you can set the width of the Label equal to the required text width.
Thanks,
ceTe Software Support Team
Re: FormattedTextArea add ... at the end of first line
Forum member · Jan 31, 2007Hello,
The project I'm working on is rendering events in a calendar view. The FormattedTextArea is the text containing the event title and is displayed in a cell (so we already know the max width of the text we can display). The requirements specify that if the event title is longer that the width of the cell to add the "..." at the end. Since we cannot add the ... directly at the end of the text after determining where the text will be truncated,inside the cell instead of adding just the formattedTextArea, we also add another label with the "..." so the width of the cell is split between the FormattedTextArea and Label, hence the text is no longer centered.
Please let me know if you find another way of tackling this problem. Thank you very much for your help!
Re: FormattedTextArea add ... at the end of first line
Support · Feb 1, 2007Hello,
After looking into it a little further, there was one workaround that might work for you but it is not the most efficient way of doing in particularly if the formatted text string is going to be large enough.
You will have to create a FormattedTextArea and add the text to it. Then check if it has any overflow. If it does have, get the substring of text that fits on the page. This will be trial and error method to find out the string by breaking the main formatted string each time and then checking for overflow. Once you find the string that fits without overflow, strip of the last word using some logic and then concatenate the ... to the string and then add the FormattedtTextArea to the page. You will need one FormattetTextArea for each substring. Following this method may solve the text alignment issue.
Thanks,
ceTe Software Support Team
Re: FormattedTextArea add ... at the end of first line
Forum member · Feb 5, 2007Hello,
"You will have to create a FormattedTextArea and add the text to it. Then check if it has any overflow. If it does have, get the substring of text that fits on the page. This will be trial and error method to find out the string by breaking the main formatted string each time and then checking for overflow."
Can you please give me an example of how do I get "the substring of text that fits on the page", formattedTextArea.Text gets the entire string...
Thanks.
Re: FormattedTextArea add ... at the end of first line
Support · Feb 5, 2007Hello,
You will have to use some logic to keep making the string of formatted text smaller by stripping words each time until the FormattedTextArea has no overflow. This will have to be done within a while loop. Yes, you are correct, the Text proeprty of FormattedTExtArea will return the complete text.
Thanks,
ceTe Software Support Team
Re: FormattedTextArea add ... at the end of first line
Forum member · Sep 6, 2012Hi,
"Text can not be read on an overflow FormattedTextArea."
giving above error while getting text from FormattedTextArea or please let me know how to get the overflow text from FormattedTextArea.
thanks
yashwant
Re: FormattedTextArea add ... at the end of first line
Support · Sep 7, 2012Hello Yashwant,
It is not possible to get the text from the overflow FormattedTextArea using our DynamicPDF Generator for .NET product.
Thanks,
ceTe Software Support Team.