You can manipulate widths of cells using cell.ColSpan property before adding that table in paragraph collection of the page. You may devise a mathematical expression to calculate column span based on width of page, text fragment and page margins, as per your requirements. A simple code snippet explaining the approach has been shared below for your kind reference.
// Instantiate Document object
Document doc = new Document();
// Create table instance
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set width for table cells
table.ColumnWidths = "60 60";
table.DefaultCellBorder = new BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
// Create row object and add it to table instance
Aspose.Pdf.Row row = table.Rows.Add();
// Create cell object and add it to row instance
Aspose.Pdf.Cell cell1 = row.Cells.Add();
// Add textfragment to paragraphs collection of cell object
cell1.Paragraphs.Add(new TextFragment("First Wide cell"));
// Add another cell to row object
Cell cell2 = row.Cells.Add();
TextFragment fragment = new TextFragment("Second cell");
cell2.Paragraphs.Add(fragment);
// Create page object and add it to pages collection of document instance
Aspose.Pdf.Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
Console.WriteLine("Fragment Width: " + fragment.Rectangle.Width);
Console.WriteLine("Page Width: " + page.PageInfo.Width);
Console.WriteLine("Page Margins: " + page.PageInfo.Margin.Right + page.PageInfo.Margin.Left);
// Calclate suitable column span based on above Widths and margins
cell1.ColSpan = 2;
// Add table to paragraphs collection of page object
page.Paragraphs.Add(table);
dataDir = dataDir + "TwoCells_18.11.pdf";
// Save PDF file
doc.Save(dataDir);
We hope this will be helpful. Please feel free to contact us if you need any further assistance.
The good news that we accomplished the desired result using a similar approach based on setting the width of the last/right cell to the width of a the TextFragment containing the text of the cell.
We are glad to know that you have accomplished your requirements with similar approach. Please keep using our API and in event of any further query, feel free to ask.