Hi, I have a table in which I have a header with 2 headers below it. I'm trying to replicate this with your library but I cannot find the way. How can this be made? Thank you
Generate PDF MultiHeader .NET
Re: Generate PDF MultiHeader .NET
Support · Jun 25, 2021Hello,
You can achieve this by adding cells and setting column span as needed.
Here is a code sample.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
//Create TableA...................
Table2 tableA = new Table2(0, 0, 200, 600);
tableA.Border.Width = 0.1F;
tableA.CellDefault.Border.Width = 0.1F;
// Add columns to the table
tableA.Columns.Add(100);
tableA.Columns.Add(100);
// Add rows to the table and add cells to the rows
Row2 row1 = tableA.Rows.Add();
row1.CellDefault.Align = TextAlign.Center;
row1.CellDefault.BackgroundColor = RgbColor.AliceBlue;
Cell2 cellR1C1 = row1.Cells.Add("MAIN HEADER");
cellR1C1.ColumnSpan = 2;
Row2 row2 = tableA.Rows.Add();
row2.CellDefault.Align = TextAlign.Center;
row2.CellDefault.BackgroundColor = RgbColor.LightYellow;
Cell2 cellR2C1 = row2.Cells.Add("Header 1");
Cell2 cellR2C2 = row2.Cells.Add("Header 2");
Row2 row3 = tableA.Rows.Add();
Cell2 cellR3C1 = row3.Cells.Add("Item 1");
Cell2 cellR3C2 = row3.Cells.Add("Item 2");
// Add the table to the page
page.Elements.Add(tableA);
// Save the PDF
string pdfFilePath = @"C:\Temp\MyTable.pdf";
document.Draw(pdfFilePath);
Thanks,
ceTe Software Support Team