table.SetColumnWidth giving FUNKY results

We are building a PDF utilizing aspose.pdf and aspose.cells. We dynamically create the table from data in the DB and calculated fields. We then add the table to the PDF.Section.Paragraph and then resize the Table. To resize, we have the following function:

public static void SizeGrid(Pdf pdfReport, Table table)
{
table.ColumnAdjustment = ColumnAdjustmentType.Customized;
table.ColumnWidths = “”;

// find out max columns
int nMaxColumns = 0;
for(int i = 0; i < table.Rows.Count; i++)
nMaxColumns = Math.Max(nMaxColumns, table.Rows[i].Cells.Count);

// now size them
for (int i = 0; i < nMaxColumns; i++)
{
float fWidth = table.GetMaxColumnWidth(pdfReport, i);
table.SetColumnWidth(i, fWidth);
}
}

The issue we are having is that the last column in the table is not getting its correct size set. The column is much larger than we want it to be. There is no column spanning going on etc. Attached is a picture of the output we get.

I have also gone around the above function by setting the sized manually as follows:

grid.SetColumnWidth(0, 80);
grid.SetColumnWidth(1, 60);
grid.SetColumnWidth(2, 50);
grid.SetColumnWidth(3, 50);
grid.SetColumnWidth(4, 50);
grid.SetColumnWidth(5, 40);
grid.SetColumnWidth(6, 80);
grid.SetColumnWidth(7, 60);
grid.SetColumnWidth(8, 30);
grid.SetColumnWidth(9, 30);
grid.SetColumnWidth(10, 30);
grid.SetColumnWidth(11, 30);
grid.SetColumnWidth(12, 30);
grid.SetColumnWidth(13, 30);

It gives the same result. Can anyone tell me why the last column is somehow getting set by itself and to big?


Hi,

It looks like your issue is related to Aspose.Pdf product, so I will move this thread to Aspose.Pdf forum.

As a side note, Aspose.Cells for .NET now supports to directly convert Excel spreadsheets to PDF documents without using Aspose.PDF product any more, see the document for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/converting-to-pdf-files.html

Also, if you are using Aspose.Cells API and need to auto-fit column widths according to the contents in the cells, you may use its auto-fit feature before saving to PDF document, see the document for reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/autofit-rows-columns.html

Thank you.


Hello Scott,

Thanks for using our products.

I am a representative from Aspose.Pdf team. I have tested the scenario using Aspose.Pdf for .NET 4.7.0 using the code snippet shared over Integrate Table with Database and I am unable to notice the problem. The width of columns is adjusted as I have specified against ColumnWidths property of Table class. Can you please share which version of Aspose.Pdf for .NET you are using ?

In case you are also using version 4.7.0 and the problem is not resolved, please share the complete code snippet so that we can test the scenario at our end. We apologize for your inconvenience.