【问题标题】:Add table at the bottom of the page (Aspose)在页面底部添加表格(Aspose)
【发布时间】:2021-03-13 14:04:58
【问题描述】:

我使用 Aspose.PDF 在我的页面中添加表格。但我需要在页面底部和水平中心添加一个表格。 我使用table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow; 将表格添加到水平中心, 但我无法获得桌子的高度,也无法暴露table.Margin。我怎样才能找到桌子的高度?或者如何将我的表格添加到底部?

【问题讨论】:

    标签: c# .net aspose aspose.pdf


    【解决方案1】:

    请尝试使用以下代码在 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 official support forum 创建一个主题,您的问题将得到相应的解决。我是 Asad Ali,我在 Aspose 担任开发人员宣传员。

    【讨论】:

    • 谢谢,但我的做法不同
    猜你喜欢
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 2021-07-18
    • 2013-09-12
    • 2018-06-30
    • 2013-11-18
    相关资源
    最近更新 更多