We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

String Text Wrap

Thread ID:

Created:

Updated:

Platform:

Replies:

126980 Oct 19,2016 01:32 PM UTC Nov 8,2016 08:46 AM UTC UWP 5
loading
Tags: Pdf
Corey Powell
Asked On October 19, 2016 01:32 PM UTC

RectangleF answerRec = new RectangleF(20, 100, 520, 100);
            PdfPen borsder = new PdfPen(new PdfColor(51, 0, 0));
            graphics.DrawRectangle(borsder, answerRec);
            PdfFont answerF = new PdfStandardFont(PdfFontFamily.TimesRoman, 8);
            PdfTextElement answer = new PdfTextElement(peopleQ1comments, answerF);
            answer.Draw(page2, new PointF(answerRec.Left, answerRec.Top + 4));

in the above code "peopleQ1comments" is a string of text, when I create the PDF the text runs out of the "RectrangleF" & off the page, how do I wrap the text within the "answerRec"

Gayathri Ramalingam [Syncfusion]
Replied On October 20, 2016 06:49 AM UTC

Hi Corey, 
Thank you for using Syncfusion Products. 
When we use Draw() method with PointF, the text will be truncated. Because by default the height and width for the text will be assigned as 0. So if we want to display the full text, we need to provide the appropriate height and width manually using RectangleF. 
The text can be wrapped into the RectangleF by using the below code snippet, 
//Set the bounds value. 
RectangleF bounds = new RectangleF(20,100,495,100); 
//Draw the rectangle. 
page.Graphics.DrawRectangle(pen, bounds); 
// Draw the text element. 
element.Draw(page, bounds, layoutFormat);  
 
We have prepared a sample to wrap the text inside the RectangleF. Please find the sample in the below link, 
 
With Regards, 
Gayathri R 


Corey Powell
Replied On November 1, 2016 02:53 PM UTC

Thank you for your response, I have implemented the code, but when the PDF is generated the text is not wrapped in the box, not sure where I am going wrong, my code is below

RectangleF answerRec = new RectangleF(20, 65, 520, 40);
            PdfPen border = new PdfPen(new PdfColor(51, 0, 0));
            graphics.DrawRectangle(border, answerRec);
            PdfFont answerF = new PdfStandardFont(PdfFontFamily.TimesRoman, 6);
            PdfTextElement answer = new PdfTextElement(peopleQ1comments, answerF);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify, PdfVerticalAlignment.Top);
            format.ParagraphIndent = 5f;
            format.WordWrap = PdfWordWrapType.Word;
            answer.StringFormat = format;
            answer.Draw(page2, new PointF(answerRec.Left, answerRec.Top + 4));



Gayathri Ramalingam [Syncfusion]
Replied On November 2, 2016 11:24 AM UTC

Hi Corey, 
 
Thank you for your update. Please find the details of your queries in the below table, 
Query 
Details 
 I have implemented the code, but when the PDF is generated the text is not wrapped in the box, not sure where I am going wrong, my code is below
 
RectangleF answerRec = new RectangleF(20, 65, 520, 40);
            PdfPen border = new PdfPen(new PdfColor(51, 0, 0));
            graphics.DrawRectangle(border, answerRec);
            PdfFont answerF = new PdfStandardFont(PdfFontFamily.TimesRoman, 6);
            PdfTextElement answer = new PdfTextElement(peopleQ1comments, answerF);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify, PdfVerticalAlignment.Top);
            format.ParagraphIndent = 5f;
            format.WordWrap = PdfWordWrapType.Word;
            answer.StringFormat = format; 

            answer.Draw(page2, new PointF(answerRec.Left, answerRec.Top + 4)); 
On analyzing your code snippet, we came to know that you have used PointF to draw the string. As mentioned in the previous update, When we use Draw() method with PointF, the text will be truncated. Because by default the height and width for the text will be assigned as 0. Due to this, the text has been truncated. We need to provide appropriate height and width manually using RectangleF. So, please draw the string using RectangleF instead of using PointF.   
 
Please find the below code snippet, 
             
answer.Draw(page2, answerRec); 

With Regards, 
Gayathri R 


Corey Powell
Replied On November 7, 2016 01:20 PM UTC

Thank you for the support

Gayathri Ramalingam [Syncfusion]
Replied On November 8, 2016 08:46 AM UTC

Hi Corey,  
Thank you for your update. 
 
With Regards, 
Gayathri R 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;