|103506||May 8,2012 10:14 AM||May 9,2012 08:04 AM||ASP.NET Web Forms (Classic)||1|
Hello. Has anyone experienced an issue in generate a PDF where it is wrapping text to the next line in the middle of the word?
We are using Syncfusion v220.127.116.11 in our ASP.NET 3.5 C# application to generate a PDF by parsing a dynamically-created XML document and continuously calling the draw method of a PdfTextElement object. We are keeping track of the “position” on the page of where the “cursor” last wrote text. The X coordinate of this position is used to set the ParagraphIndent property of the StringFormat object of the PdfTextElement. The Y coordinate of the last position is used to create a RectangleF called “bounds”, with the starting point being (0,Y) and the size being the graphics client size’s width and height – Y (remaining page height). This “bounds” RectangleF is passed to the draw method of the PdfTextElement object with the current page’s graphics and layout format. See the code snippet below.
99% of the time, the text wraps perfectly. But it seems when the ParagraphIndent is set too close to the width of the page’s graphics, Syncfusion gets “confused” and does not move the entire word to the next line, instead breaking up the word onto two lines. I had a similar problem when drawing text too close to the bottom of the page and was able to create a work-around in the code, but I’m having difficulty doing the same for the page width. The page is set for each section of the PDF so that the size is Letter and to have left and right margins of 60f.
I’d appreciate any thoughts and feedback on why Syncfusion is wrapping mid-word.
//Create text element with font and
PdfTextElement text = new PdfTextElement(str_text);
text.Font = _prvGetPdfFont(style);
text.Brush = _prvGetPdfBrush(style);
//Set up string format
PdfStringFormat stringFormat = new PdfStringFormat();
stringFormat.MeasureTrailingSpaces = true;
stringFormat.Alignment = _prvGetAlignment(style);
text.StringFormat = stringFormat;
//Layout Format setup
PdfLayoutFormat layoutFormat = new PdfLayoutFormat();
layoutFormat.Break = PdfLayoutBreakType.FitPage;
layoutFormat.Layout = PdfLayoutType.Paginate;
//Set the text to begin at the last
text.StringFormat.ParagraphIndent = _prvPDFCurrentLocation.X;
//Set bounds to be page width and the
page remaining height based on last vertical position
PointF location = new PointF(0, _prvPDFCurrentLocation.Y);
SizeF size_bounds = new SizeF(_prvPDFCurrentPage.Graphics.ClientSize.Width, _prvPDFCurrentPage.Graphics.ClientSize.Height - location.Y);
RectangleF bounds = new RectangleF(location, size_bounds);
//Draw the text to the page
text.Draw(this._prvPDFCurrentPage, bounds, layoutFormat);
Thank you for your interest in Syncfusion products.
The PdfWordWrap.Word enumeration is implemented as explained in the description: “Text is wrapped by words. If there is a word that is longer than bounds' width, this word is wrapped by characters”. Hence this behavior is by design. However, could you please create a direct trac incident with these details so that we can analyze it?
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.