Добавить таблицу внизу страницы (Aspose)

Я использую Aspose.PDF для добавления таблицы на свою страницу. Но мне нужно добавить таблицу внизу страницы и по центру по горизонтали. Я использую table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow; для добавления таблицы в центр по горизонтали, но не могу получить высоту таблицы и не могу выставить table.Margin. Как узнать высоту стола? Или как я могу добавить свою таблицу в конец?


person Unnamed    schedule 13.03.2021    source источник


Ответы (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");

Чтобы получить высоту таблицы, вы можете использовать метод GetHeight() класса Table. Например, в приведенном выше примере кода вы можете использовать double height = tab1.GetHeight();. Если у вас возникнут проблемы с выполнением требований, вы можете создать тему на форуме официальной поддержки Aspose.PDF. где ваши проблемы будут рассмотрены соответствующим образом. Это Асад Али, и я работаю разработчиком-евангелистом в Aspose.

person Asad Ali    schedule 16.03.2021
comment
Спасибо, но я сделал по другому - person Unnamed; 20.03.2021