在页面底部添加table(Aspose)

Add table at the bottom of the page (Aspose)

我使用 Aspose.PDF 在我的页面中添加 table。但是我需要在页面底部和水平居中添加一个table。 我使用 table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow; 将 table 添加到水平中心, 但我无法获得 table 的高度,也无法公开 table.Margin。我如何找到 table 身高?或者如何将我的 table 添加到底部?

请尝试使用以下代码在 PDF 页面底部添加 Table。您可以使用 HeaderFooter Class 和 Page.Footer 属性 来实现您的要求。

// 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");

为了得到table的高度,可以使用TableClass的GetHeight()方法。例如,在上面的代码示例中 - 您可以使用 double height = tab1.GetHeight();。如果您在实现要求时遇到任何问题,请在 Aspose.PDF official support forum 中创建一个主题,您的疑虑将得到相应的解决。我是 Asad Ali,我在 Aspose 担任开发人员布道师。