Put two tables right next to each other

I'm using Aspose.pdf and having trouble how to put two tables. Can some one help me with this or lead me into the right direction?

For example I would like this setup

Table 1 Table 2

Table 3 - centered under these two tables.

Any ideas on how to do this?

Also view this code below.

Pdf pdf = new Pdf();

// specify the left margin info for the PDF file

pdf.PageSetup.Margin.Left = new MarginInfo().Left = 40;

// specify the Right margin info for the PDF file

pdf.PageSetup.Margin.Right = new MarginInfo().Right = 40;

Section sec0 = pdf.Sections.Add();

sec0.IsNewPage = false;

Text dashboardTitle1 = new Text("Dashboard For: " + "Test 1");

sec0.Paragraphs.Add(dashboardTitle1);

Section sec1 = pdf.Sections.Add();

sec1.IsNewPage = false;

sec1.ColumnInfo.ColumnCount = 2;

//Set the spacing between the columns

sec1.ColumnInfo.ColumnSpacing = "5";

//sec1.ColumnInfo.ColumnWidths = "200 200";

Text dashboardTitle2 = new Text("Dashboard For: " + "Test 2");

sec1.Paragraphs.Add(dashboardTitle2);

Text dashboardTitle3 = new Text("Dashboard For: " + "Test 3");

dashboardTitle3.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Left;

sec1.IsNewColumn = true;

sec1.Paragraphs.Add(dashboardTitle3);

//Display the PDF in Web Page

pdf.Save("title", SaveType.OpenInBrowser, Response);

How come dashboardTitle2 and dashboardTitle3 aren't columns?

The output is

dashboardTitle2

dashboardTitle3

I would like

Dashboard 1 centered

Dashboard 2 Dashboard 3

Thanks,
Jr.

Hello Ruperto,

Thanks for considering Aspose.

Regarding your first requirement on placing tables side by side, its better to first create a main table and place the other tables inside the main table (table inside a table). Please take a look over the following code snippet and the resultant PDF that I have attached.

[C#]

//Instantiate a Pdf instance
Pdf pdf1 = new Pdf();
//Create a section in the Pdf instance
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//Create a main outer table

Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
//Add the table into the paragraphs collection of section
sec1.Paragraphs.Add(tab1);
//Set the column widths of the table
tab1.ColumnWidths = "120 120";
//Set the default cell border using BorderInfo instance
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All);
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;

Aspose.Pdf.Color color1 = new Aspose.Pdf.Color("Pink");
//Add a row into the table
Aspose.Pdf.Row row1 = tab1.Rows.Add();
//Add 1st cell in the row
Aspose.Pdf.Cell cell1 = row1.Cells.Add();
// add the table to paragraphs collection of the cell
cell1.Paragraphs.Add(CreateInnerTable(sec1, color1));
//Add 2nd cell in the row
Aspose.Pdf.Cell cell2 = row1.Cells.Add();
cell2.Paragraphs.Add(CreateInnerTable(sec1, color1));

//Add a second row into the table
Aspose.Pdf.Row row2 = tab1.Rows.Add();
//Add 1st cell in second row
Aspose.Pdf.Cell cell3 = row2.Cells.Add();
// set the column span value to 2. Which means the cell will occupy two cells width
cell3.ColumnsSpan = 2;
// set the alignment value of the cell contents as center aligned
cell3.Alignment = AlignmentType.Center;
cell3.Paragraphs.Add(CreateInnerTable(sec1, color1));

pdf1.Save(@"d:/pdftest/TableInSideTable.pdf");

private static Aspose.Pdf.Table CreateInnerTable(Aspose.Pdf.Section secMain, Aspose.Pdf.Color color)
{
//Include table to display bottom line
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(secMain);
//Set with column widths of the table
tab1.ColumnWidths = "55 55";
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.5F,new Aspose.Pdf.Color("Maroon"));
//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo((int)BorderSide.All, .5F);
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;

//Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("Item 1,1");
row1.Cells.Add("Item 1,2");
row1.BackgroundColor = color;
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("Item 2,1");
row2.Cells.Add("Item 2,2");
return tab1;
}

I would recommend you to visit the following links for information on

Regarding your second requirement, I think its better to create a table and place the text inside it. This way you can easily specify the alignment of the text. Or you can also use FloatingBox to place your contents over the document. FloatingBox is a paragraph with absolute positioning rather than page relative positioning. For more information, please visit Working with Floating Box

In case I have not properly understood your requirements, please share some more details. It would be better if you could share some picture which can describe your requirements.

This is exactly what I was looking for. Thanks so much for the quick response.

Thanks,

Jr.