How can the non breaking space can be used to have a multiline content in a PdfPTable cell. iTextSharp is breaking down the words with the space characters.
The scenario is I want a multiline content in a table head, such as in first line it may display "Text1 &" and on second line it would display "Text", on rendering the PDF the Text1 is displayed in first line, then on second line & is displayed and on third it takes the length of the first line and truncates the remaining characters to the next line.
Or can I set specific width for each and every column of the table so as to accomodate text content within it, such as the text would wrap within that specific width.
You didn't specify a language so I'll answer in VB.Net but you can easily convert it to C# if needed.
To your first question, to use a non-breaking space just use the appropriate Unicode code point
U+00A0
:In VB.Net you'd declare it like:
And in C#:
Then you can just concatenate it where needed:
You might also find the non-breaking hyphen (U+2011) helpful, too.
To your second question, yes you can set the width of every column. However, column widths are always set as relative widths so if you use:
What you are actually saying is that for the given table, the first column should be twice as large as the second column, you are NOT saying that the first column is 2px wide and the second is 1px. This is very important to understand. The above code is the exact same as the next two lines:
The column widths are relative to the table's width which by default (if I remember correctly) is 80% of the writable page's width. If you would like to fix the table's width to an absolute width you need to set two properties:
Putting the above all together, below is a full working WinForms app targetting iTextSharp 5.1.1.0: