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. Image for the cookie policy date

Pdf: add text with word wrapping - and return new height

Is it possible to generate a string in a pdf, that will wrap at a specific width, but continue to grow height, and then return the height, or y bottom coordinate of the result.

Currently - I see you can word wrap with a specific Rect:
PdfStringFormat format = new PdfStringFormat
WordWrap = PdfWordWrapType.Word
var rect = new RectangleF(x, y, maxWidth.Value, 100);
CurrentPageGraphics.DrawString(text, font, brush, rect, format);

... but here, 100 is the height. I'm looking for something along the lines of a PdfLayoutResult after wrapping text that is limited only by width, and not by height.

2 Replies

MJ Malcolm Jack August 15, 2019 06:17 AM UTC

I think I have what I'm looking for:

        PdfTextElement element = new PdfTextElement(text, font, brush);
PdfStringFormat format = new PdfStringFormat
WordWrap = PdfWordWrapType.Word
element.StringFormat = format;
RectangleF bounds = new RectangleF(x, y, maxWidth, maxHeight);
result = element.Draw(CurrentPage, bounds);

PV Prakash Viswanathan Syncfusion Team August 15, 2019 09:19 AM UTC

Hi Malcolm, 

Thank you for contacting Syncfusion support.  

Yes it is possible to draw the text to PDF page and get the rendered layout result using PdfLayoutResult class. Please refer below link for more information about rendering text with specified bounds and getting a rendered result (Bounds).  

Please let us know if you need any  further assistance on this.  

Prakash V 

Live Chat Icon For mobile
Up arrow icon