How do I align tables one beside the other without any spacing so it looks like its just one table.

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Merger for .NET (v8.x)  /  Display Thread

DynamicPDF Merger for .NET (v8.x) Forum

I have  a table with 2 columns and 4 rows. I have an other table with just one row and one column. Lets say the first table has data as follows;

     Table 1
Channel1       Pass
Channel2       Fail
Channel3       Pass
Channel4       Fail

Now table 2 is as follows

    Table2 
    Pass

Now I want table 2 to be taking the same height and width as table1 and it needs to start exactly beside the table 1 so both of them looks like it is one table. Can you please post some pseudo code. Also if You can explain how I can get the "Table 1" and "Table 2" headings that will be great.
Posted by a ceTe Software moderator
Hello,

You can achieve your requirement by adding two tables to the PDF. You will need to set the calculated X position to the second table to place it besides the first one. Below is the code sample.

            Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);

            //build first table by adding rows and columns.
            Table2 table1 = new Table2(0,0,200,20);
            Column2 colT1C1 = table1.Columns.Add(100);
            Column2 colT1C2 = table1.Columns.Add(100);

            Row2 rowT1Header = table1.Rows.Add();
            Cell2 cellT1H1 = rowT1Header.Cells.Add("HEADER 1");
            Cell2 cellT1H2 = rowT1Header.Cells.Add("HEADER 2");

            for(int i=0;i<4;i++)
            {
                Row2 rowT1R1 = table1.Rows.Add();
                Cell2 cellT1C1 = rowT1R1.Cells.Add("text"+(i+1));
                Cell2 cellT1C2 = rowT1R1.Cells.Add("text"+(i+1));

            }
            table1.Height = table1.GetRequiredHeight();
            page.Elements.Add(table1);

            //build second table by adding rows and columns.
            float xPosition = table1.X+table1.Width;
            float yPosition = table1.Y;

            Table2 table2 = new Table2(xPosition, yPosition, 100, 20);
            Column2 colT2C1 = table2.Columns.Add(100);
            Row2 rowT2Header = table2.Rows.Add();
            Cell2 cellT2H1 = rowT2Header.Cells.Add("T2 HEADER 1");
            for (int i = 0; i < 4; i++)
            {
                Row2 rowT2R1 = table2.Rows.Add();
                Cell2 cellT2C1 = rowT2R1.Cells.Add("Table2 Text" + (i + 1));
            }
            table2.Height = table2.GetRequiredHeight();
            page.Elements.Add(table2);
            document.Draw(@"C:\Temp\MyDocument.pdf");

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 11:32 PM.