Add table after another table on same page.

Add table after another table on same page.

Forum member · Jun 8, 2021
Hi Team, I need help in adding table in a page after another table on same page. Its overlapping the way i did. As per my requirement i need to add one table after another. Example : I have first table that having 100 rows then it takes 5 and half pages, now i want to add another table that need to start from same page after providing some spaces.

Re: Add table after another table on same page.

Support · Jun 8, 2021
Hello, Yes, you can add tables one below the other without any problem using our DynamicPDF Core Suite for .NET product. You will need to keep track of Y position, available height and then accordingly add the table to a page. Here is a code sample. class SampleTable { Document document; Page page; float availableHeight; float currentX = 0; float currentY = 0; float padding = 10; string text = "This is to test"; //float heightUtilized = 0; public SampleTable() { } public void BuildTable() { //Create the Document document = new Document(); //Create a page page = new Page(); text += text; //Create a table Table2 table; //array list to create a list of table and Label objects ArrayList tableList = new ArrayList(); Table2 table1 = new Table2(0, 0, 500, 0); table1.Height = table1.GetRequiredHeight(); table1.Columns.Add(100); table1.Columns.Add(400); for (int i = 0; i < 20; i++) { Row2 row = table1.Rows.Add(20); row.Cells.Add("Row #"); row.Cells[0].Splittable = true; string text1 = "Hello Cete"; row.Cells.Add(text1); row.Cells[1].Splittable = true; } //tableList.Add(table1); //Creating tables and adding them to a array list for (int p = 1; p < 10; p++) { table = new Table2(0, 0, 100, 0); table.Columns.Add(530); Row2 row1 = table.Rows.Add(); Cell2 cell1 = row1.Cells.Add("Table " + p.ToString()); cell1.Splittable = true; for (int j = 0; j < 200; j++) { Row2 row2 = table.Rows.Add(); Cell2 cell22 = row2.Cells.Add(text + j.ToString()); cell22.Splittable = true; } table.Height = table.GetRequiredHeight(); tableList.Add(table); } //Add the first page to the document AddPage(); //Add the all tables to the document in a for loop for (int k = 0; k < tableList.Count; k++) { AddTable((Table2)tableList[k]); } //save the pdf to disk. document.Draw(@"C:\Temp\table.pdf"); System.Diagnostics.Process.Start(@"C:\Temp\table.pdf"); } private void AddTable(Table2 table) { do { //set X, Y of the table. table.X = currentX; table.Y = currentY; float pageht = page.Dimensions.Body.Height; availableHeight = pageht - currentY; //Compare the height of the table and the available height on the page. //set the table height according to it. if (table.GetRequiredHeight() > availableHeight) table.Height = availableHeight; else table.Height = table.GetRequiredHeight(); //add the table to the page. page.Elements.Add(table); currentY = currentY + table.Height + padding; //Add a new page when there is no place to add new elements to the page if (currentY > (page.Dimensions.Body.Height)) { //Adds a new page AddPage(); } //get the overflow table table = table.GetOverflowRows(); } while (table != null); } private void AddPage() { //create a page page = new Page(); //reset the available the currentY to ooriginal positions. currentY = 0; //add the page to the document. document.Pages.Add(page); } } Thanks, ceTe Software Support Team