I have a requirement to display tables vertically on a page in .NET. I have only two columns so when the first half of the page is filled then it should not move to next page but continue on the same page in the other half..
Column 1 Column 2 Column 1 column 2
1 8
2 9
3 10
4 11
5 12
6 13
7 14
Could you please help.
Tables to be aligned vertically
Re: Tables to be aligned vertically
Support · Aug 29, 2012Hello,
Yes, you can achieve your requirement without any problem using our DynamicPDF Generator for .NET product. You will need to set the desired X and Y positions to the overflow table while getting the over flow rows using GetOverflowRows method which takes X and Y position values as arguments. Below is the sample code for it.
Document document = new Document();
float tableXPosition=0;
float tableYPosition=0;
//Build table.
Table table = new Table(tableXPosition, tableYPosition, 100, 400);
table.RepeatColumnHeaderCount = 1;
//Adding Columns to the table.
Column column1 = table.Columns.Add(50);
Column column2 = table.Columns.Add(50);
//Add header row to the table.
Row headerRow = table.Rows.Add(20);
Cell headerCell1 = headerRow.Cells.Add("Column1");
headerCell1.BackgroundColor = RgbColor.Gray;
headerCell1.VAlign = CellVAlign.Center;
headerCell1.Align = CellAlign.Center;
Cell headerCell2 = headerRow.Cells.Add("Column2");
headerCell2.BackgroundColor = RgbColor.Gray;
headerCell2.VAlign = CellVAlign.Center;
headerCell2.Align = CellAlign.Center;
//Adding rows to the table.
for (int i = 0; i < 130; i++)
{
Row row = table.Rows.Add(20);
Cell cell1 = row.Cells.Add(""+i);
cell1.VAlign = CellVAlign.Center;
cell1.Align = CellAlign.Center;
Cell cell2 = row.Cells.Add(""+i);
cell2.VAlign = CellVAlign.Center;
cell2.Align = CellAlign.Center;
}
do
{
Page page = new Page();
document.Pages.Add(page);
if (table.GetRequiredHeight() > page.Dimensions.Body.Height)
{
table.Height = page.Dimensions.Body.Height;
}
else
{
table.Height = table.GetRequiredHeight(); ;
}
page.Elements.Add(table);
tableXPosition=table.X+table.Width+100;
tableYPosition=table.Y;
table = table.GetOverflowRows(tableXPosition, tableYPosition);
if ( table!= null )
{
page.Elements.Add(table);
table = table.GetOverflowRows(0, 0,100,table.GetRequiredHeight());
}
}
while (table != null);
document.Draw(@"C:\Mydocument.pdf");
Thanks,
ceTe Software Support Team.
Re: Tables to be aligned vertically
Forum member · Aug 30, 2012I am using RenderTableCell function to render the tables so at the time of rendering itself how can I achieve this.
here is the code I am using
My table is of form [ceTe.DynamicPDF.PageElements.Table2 table]
foreach(int i in object)
{
base.RenderTableRow(table, ref arow);
base.RenderTableCell(table, ref arow, ref aCell, object.value1.ToString(), 0, 0);
base.RenderTableCell(table, ref arow, ref aCell, object.value2, 0);
}
Re: Tables to be aligned vertically
Support · Aug 30, 2012Hello,
It is suggested to build the complete table by adding rows and dynamic contents to cell in a row. Once the table built completely then you can add it to the page depending on your requirement by specifying the X and Y positions for the overflow table. You can use the similar logic which we posted in do while loop to add the tables in a same page by setting calculated X and Y positions.
Thanks,
ceTe Software Support Team.