Unnamed
Unnamed

Reputation: 15

Add table at the bottom of the page (Aspose)

I use Aspose.PDF to add table in my page. But I need to add a table to the bottom of the page and horizontal center. I use table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow; to add table to the horizontal center, but I cannot get the height of the table and I cannot expose table.Margin. How I can find table height? Or how I can add my table to the bottom?

Upvotes: 0

Views: 1540

Answers (1)

Asad Ali
Asad Ali

Reputation: 361

Please try to use the code below in order to add a Table at the bottom of the PDF Page. You can use HeaderFooter Class and Page.Footer Property to achieve your requirements.

// Instantiate Document instance by calling an empty constructor
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
// Create a page in the pdf document
Aspose.Pdf.Page page = pdfDocument.Pages.Add();

// Create a Header Section of the PDF file
Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();
// Set the Odd Header for the PDF file
page.Footer = footer;
// Set the top margin for the header section
footer.Margin.Top = 20;

// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
footer.Paragraphs.Add(tab1);
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
tab1.HorizontalAlignment = HorizontalAlignment.Center;
// Set with column widths of the table
tab1.ColumnWidths = "100%";

// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();

row1.Cells.Add("Table in Footer Section");
row1.BackgroundColor = Color.Gray;
// Set the row span value for first row as 2
tab1.Rows[0].Cells[0].Alignment = HorizontalAlignment.Center;
tab1.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor = Color.Cyan;
tab1.Rows[0].Cells[0].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica");
           
// Save the Pdf file
pdfDocument.Save(dataDir + "TableInFooterSection_out.pdf");

In order to get the height of a table, you can use GetHeight() method of Table Class. For example, in the above code sample - you can use double height = tab1.GetHeight();. In case you face any issue while achieving your requirements, you can please create a topic in Aspose.PDF official support forum where your concerns will be addressed accordingly. This is Asad Ali and I work as Developer Evangelist at Aspose.

Upvotes: 2

Related Questions