We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word wrap in table cells for PDF generation

I have a simple test that shows odd behavior with word wrapping. If I size the column to just the right size, the PDF will have the last character of the word on the second line. If I make the column slightly smaller, the entire last word will go to the second line. If I make it slightly larger, it will all fit on the same line.

Here is the code I used to generate the attached PDF.

using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Pdf;

namespace DummyTestExecutor
class PDFWordWrap

public static void Main()

//Create pdf document
Pdf pdf1 = new Pdf();

Section page = pdf1.Sections.Add();

AddText(page, 204);
AddText(page, 203);
AddText(page, 202);
AddText(page, 201);
AddText(page, 200);



private static void AddText(Section page, int columnWidth)
Table layout = new Table();
layout.ColumnWidths = columnWidth.ToString();

Row titleRow = layout.Rows.Add();
titleRow.FixedRowHeight = 40;
Cell tc = titleRow.Cells.Add();

Text text = new Text();

text.Segments.Add(new Segment("Engine: 1.8L I-4 SOHC 16-Valve i-VTEC"));

Is there something I am doing wrong here?

Hello Chris,

Thanks for considering Aspose.

As far as I've tested the scenario I'm unable to notice the problem. When the Column width is equal to the width of Text, the text is displayed properly but when it starts decreasing and it gets difficult to accommodate the text inside it, the text by default wraps to the next line. When the width of the column is too less to accommodate the complete word, it is also moved to next line (the last line).

I've attached an image file explaining the scenario and also have the resultant PDF document that I've generated using Aspose.Pdf for .NET v4.1.0.0

In case it does not satisfy your query, can you please elaborate your requirement.

Hi Nayyer,

We are also experiencing this phenomenon; please see the attached example. The first sentence (“Measuring the size of the economy”) wraps as one would expect, however in the second sentence (“Measuring the cost of living”), only the last character wraps.

Perhaps I misunderstood your explanation; I expect “i-VTEC” would move to the next line if the whole sentence could not fit. We think spaces are the logical point to break the text, so in our case the word “living” should all move to the next line, as the word “economy” did.

Can you please clarify?




Thanks for your patience.

I have again tested the scenario and have analyzed that when the width of table cell is not enough to accommodate the complete sentence, it should wrap the whole word instead of its characters. For the sake of correction, I have logged it in our issue tracking system as PDFNET-24749. We will investigate this issue in details and will keep you updated on the status of a correction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We apologize for your inconvenience.

The issues you have found earlier (filed as 24749 ) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I have a much later version (version 7.4) and it appears that this is still an issue. Could really use some help. Thanks.

Hi there,

Thanks for your inquiry. Can you please download and try latest version of Aspose.Pdf for .NET 8.2. Hopefully your issue will be resolved. If issue persist then please share your sample code here. So we will test the scenario and will provide you information accordingly.

Sorry for the inconvenience faced.

Best Regards,

I downloaded the latest version and i am still getting the issue. I have attached a screenshot. Notice the word "encounter" is split on two lines. Also here is a sample of the code I am using:

var pdf = new Pdf();

Section section = pdf.Sections.Add();
var text = new Text(section, strHtml); //The Html is valid html. There are no inadvertent spaces in the middle of words
var header = new HeaderFooter(section);
section.EvenHeader = header;
section.OddHeader = header;
var txth = new Text(string.Format("Patient Name: {0}", "Test Patient"));
txth.Margin.Top = 10;
txth.TextInfo.FontName = "Verdana";
txth.TextInfo.FontSize = 9;


text.IsHtmlTagSupported = true;
text.TextInfo.FontName = "Verdana";
text.TextInfo.FontSize = 9;
text.IsAlignedByWord = true;
text.TextInfo.Color = new Aspose.Pdf.Generator.Color("Olive");


pdf.Save(strDocumentPath);var pdf = new Pdf();

Your help is appreciated.

Hi there,

Sorry for the inconvenience faced. While using the latest version of Aspose.Pdf for NET 8.2.0, I've managed to reproduce this issue on my side and logged the issue in our bug tracking system as PDFNEWNET-35546 for further investigation and resolution. I've also linked your request to this issue and you will be notified via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-35546) have been fixed in Aspose.Pdf for .NET 9.5.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi there,

Thanks for your inquiry. As stated above your reported issue, PDFNEWNET-35546, has been fixed in Aspose.Pdf for .NET 9.5.0. Please use following code snippet to add HTML string in PDF document using DOM approach.

string outFile = “35546.pdf”;<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

HtmlFragment text2 = new HtmlFragment("Chief Complaint - testing AO-10079 - first encounter : Description - The template used for this FIRST encounter is Dhana3.1template0617 THis is free text entered in the Cheif complaint section and I am making this long on purpose to see how it gets handed as a long piece of nonbreaking text.");



Please feel free to contact us for any further assistance.

Best Regards,

Can anyone confirm this has been fixed? I have to upgrade to v9.5.0 just to fix this issue. You thought it was fixed in v5.4.0 and v8.2.0 and it wasn’t. BTW, this thread started 5 years ago.

Thank you

Hi Peter,

Thanks for your inquiry. Please note above reported issues has been fixed. Please download and try latest version of Aspose.Pdf for .NET it will help you to accomplish the task.

Moreover, actually different customers posted their queries on same thread instead instantiating new post so this thread keeps on since last 5 years.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Peter,

Adding more to Tilal’s comments, if you are still facing an issue while using our API, please share the code snippet and resultant file being generated at your end so that we can test the scenario at our end.

The issue of text wrapping MID-WORD when encased in html tags is NOT fixed in version 9.7.0. Please see the attached image. Following is the html being sent to Aspose.pdf:

Our next set of Preventative Maintenance Checks have been scheduled! On Wednesday, October 15th a member of our maintenance team will be performing service for the 17th Floor between the hours of 9:00am and 5:00pm.

This is well formed html and should render correctly. Please let me know if there’s anything else I can provide to help you.


Hi Peter,

Thanks for your inquiry. Please share your sample code here, so we will test it and provide you more information accordingly. Moreover, please note we have fixed the issue in new DOM approach to add html text in PDF document.

We are sorry for the inconvenience caused.

Best Regards,

this thread is hilarious


Thanks for contacting support.

Can you please share some details regarding the issues which you are facing, so that we can reply accordingly.