在页面底部添加表格(Aspose)



我使用Aspose.PDF在页面中添加表。但我需要在页面底部和水平中心添加一个表格。我使用CCD_ 1将表格添加到水平中心,但是我不能得到桌子的高度,并且我不能暴露CCD_ 2。我怎样才能找到桌子的高度?或者我如何将我的桌子添加到底部?

请尝试使用下面的代码,以便在PDF页面的底部添加一个表。您可以使用HeaderFooter类和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类的GetHeight()方法。例如,在上面的代码示例中,您可以使用double height = tab1.GetHeight();。如果您在满足要求时遇到任何问题,请在Aspose.PDF官方支持论坛中创建一个主题,您的担忧将得到相应的解决。我是AsadAli,我是Aspose的开发宣传员。

最新更新