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
close icon

PdfLightTable column width

Hi.

I would like to know how to set a column width in PdfLightTable such that text in the column's cells won't wrap. I need to have one such column in a table.

What I'm doing now is I measure the lengths of all strings in a one column and set the column width according to the longest string like this:

float w = maxLength + (cellPadding * 2);
table.Columns[i].Width = w; // w == 98.3786545

But when I check the column width in BeginCellLayout event, the width is 95.44846 and the longest string in the column wraps.

Does the PdfColumn.Width contain also the CellPadding and CellSpacing? I.e. if I set col.Width=10 would the actual content width be 10 - (2 * padding + 2 * spacing) or something else?

My Essential Studio version is 7.2.0.37.

Best Regards,
Asko

11 Replies

SS Sri Subhashini M Syncfusion Team September 3, 2009 11:14 AM UTC

Hi Asko,

Thank you for your interest in Essential PDF.

PdfLighTable`s Column width value calculated from the below specified factors,

1. PdfLighTables boundary width.
2. Tables cell spacing
3. Table border size.

Could you please do find the sample which demonstrates of calculating actual table size and let me know if you need any information?

http://files.syncfusion.com/samples/PDF.Windows/PDF_Window_89709.zip

Regards,
Suba


AN Asko Niemi September 7, 2009 01:29 PM UTC

Hi Suba and thanks for the example.

I'm not sure if I understood the example correctly. I attached an example where I set a column width to the value calculated as per your example and the column ends up to be much wider than needed.

What I want is that the column, whose index is passed to the ResizeColumn method, is resized to such width that none of the text strings in that column would wrap.

It seems that if I set a column width explicitly, the width is changed when I look at it in the BeginCellLayout event.

Regards,
Asko



PdfLightTableExample_ee41a3ac.zip


SS Sri Subhashini M Syncfusion Team September 8, 2009 11:12 AM UTC

Hi Asko,

I was able to reproduce the issue which you mentioned here. Could you please try the below modified sample from the below specified location and let me know if this helps?

http://files.syncfusion.com/samples/PDF.Windows/PDF_Win_F89709.zip

Regards,
Suba


AN Asko Niemi September 9, 2009 06:46 AM UTC

Hi Suba,

That worked better but still the column gets wider than necessary, i.e. there is excess white space after the longest text in its cell. That is not a big issue but it would be nice if it was possible to set a column to an exact width.

Are the column widths in millimeters? I saw that you were converted the width from points to mm.

Regards,
Asko


SS Sri Subhashini M Syncfusion Team September 11, 2009 06:58 AM UTC

Hi Asko,

We can set the exact width for the column according to the text by setting the column width as given text length. Kindly look into the code snippet,


string text = row[colIndex].ToString();
maxLength = Math.Max(maxLength, text.Length);


Could you please try the below modified sample and let me know if this helps?

http://files.syncfusion.com/samples/PDF.Windows/PDF_F89709.zip

Regards,
Suba


AN Asko Niemi September 12, 2009 07:16 AM UTC

Hi.

It seems to work up to the eighth column but if you apply the width to the 9th or 10th column, the last "word" word of the longest text will wrap to a new line.

I.e. ResizeColumn(pdfTable, dt, page.GetClientSize().Width, 7); works but ResizeColumn(pdfTable, dt, page.GetClientSize().Width, 8); does not work.

Best Regards,
Asko


SS Sri Subhashini M Syncfusion Team September 15, 2009 04:06 AM UTC

Hi Asko,

I was able to reproduce the issue which you mentioned here. But we can resolve the issue with the help of the WordWrap property of the StringFormat class.

Could you please try the below modified code snippet and let me know if this helps?


pdfTable.Columns[colIndex].StringFormat = new PdfStringFormat();
pdfTable.Columns[colIndex].StringFormat.WordWrap = PdfWordWrapType.None;
pdfTable.Columns[colIndex].Width = maxLength;


Regards,
Suba


AN Asko Niemi September 18, 2009 04:04 PM UTC

Hi Suba,

By doing that the last "word" word, e.g. in the 10th column, won't be displayed at all when there are ten words in the table cell. In the previous example the last word was wrapped to a new line.

I think I will go with the solution you subitted on 9/8/2009 7:12:58 AM. It is the most close what I'm after.

Thanks and Regards,
Asko


SS Sri Subhashini M Syncfusion Team September 23, 2009 10:47 AM UTC

Hi Asko,

I regret for the long delay in getting back with you.

I was able to reproduce the issue which you mentioned here. Could you please do find the modified sample which meets your requirement and let me know if this helps?

http://files.syncfusion.com/samples/PDF.Windows/PDF_F89709_3.zip

Regards,
Suba


AN Asko Niemi October 23, 2009 04:51 AM UTC

Hi Suba.

That last example did the trick. Thank You.

Regards,
Asko


SS Sri Subhashini M Syncfusion Team October 23, 2009 09:44 AM UTC

Hi Asko,

Glad to hear that it worked fine. Please let me know if you need any further assistance.

Regards,
Suba

Loader.
Live Chat Icon For mobile
Up arrow icon