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

Free Support Forum - aspose.com

How to set column width


I need to create PDFs using the table.ImportDataTable method as shown below, however, each datatable contains different number of columns and their width are also different in each datatable. How can I define the width size and the number of columns before importing each datatable into the PDF object? Can Aspose.PDF sets all the column widths automatically based on the data being imported?

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
tab1.ColumnWidths = "100 100 100 100"; // prefine width does not work for me. How can I define widths dynamically?
tab1.ImportDataTable(myDataTable, true, 0, 0);
pdf1.Save("asposeExportDataToPDF.pdf", Aspose.Pdf.SaveType.OpenInBrowser, this.Response);


In order to define the number of columns to be imported please refer to function public void ImportDataTable(DataTable,bool,int,byte,int,int); using this function you can define maximum number of columns to be imported.

Table class in Aspose.pdf has a property named ColumnAdjustment, which indicates how to determine the width of columns. By default the value is set to customized, which means the column width would be based over the value defined by user. If you set the value to AutoFitToContent, than the column width would be set based over data being imported.