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); |