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

Free Support Forum - aspose.com

Pdf - dom

Hi, I am trying to generate a PDF with table using dom api,

I want to set widths of my columns in table and I see setColumnWidths(“100 123 13”) works but I do not want to specify width for all columns just the ones I want. Rest can be defaults.

I tried to use cell.setWidth() but this does not work.

It’s hard to find a proper documentation for your products. I googled and it comes up with cells.setFitwidth this is not part of dom way generation of PDFs.

Please help

Hi Ritesh,

Thanks for your inquiry. I am afraid currently Aspose.Pdf does not support to set column width of specific columns and rest will take default width automatically. Either you need to set width for each column explicitly or otherwise Aspose.Pdf will set default width(100) for all columns. However as a workaround you can set column width to AutoFitToContent as following.

// Added document<o:p></o:p>

Document doc = new Document();

Page page = doc.getPages().add();

//Create a table object and add it to the paragraphs collection of the section

com.aspose.pdf.Table tab1 = new com.aspose.pdf.Table();


//Set the column widths and default cell border of the table


tab1.setColumnWidths("50 50 50");

tab1.setDefaultCellBorder(new BorderInfo(BorderSide.All, 1F));

// Create rows in the table and then cells in the rows

com.aspose.pdf.Row row1 = tab1.getRows().add();

row1.getCells().add("Sample Text");


row1.getCells().add("Its test to set column width as per contnents");

//save the resultant PDF


Please feel free to contact us for any further assistance.

Best Regards,