Header Footer with multiple line with multiple alignment.

Header Footer with multiple line with multiple alignment.

Forum member · Jun 26, 2021
Hi Team, I have a requirement of header and footer with multiple element in multiple line. Along with that i need element in different alignment. Please find the below example for more clarification. Please help me to achieve this requirement. Ex: Header Section: (Left Align) (Center Align) (Right Align) EmployeeId: EMP101 Department Code: INVT Project Code: PRJ01 Employee Name: John Department Name: INVT Project Name: FMCG *****************End of Header Section************************************* Footer Section: (Center Align) Confidential (Left Align) (Right Align) Exported Date: 04/26/2021 6:01:17 AM GMT Page 2 of 120 *****************End of Footer Section************************************* Note: Here center align element is margin at top compare to left and right align. Left and Right align should be in same line. Thanks, Chandan Singh

Re: Header Footer with multiple line with multiple alignment.

Support · Jun 28, 2021
Hello, You can achieve your requirement using the Table2 page element and a Template. Here is a code sample: // Create a PDF Document Document document = new Document(); // Add 5 blank pages to the document document.Pages.Add(new Page(PageSize.Letter)); document.Pages.Add(new Page(PageSize.Letter)); document.Pages.Add(new Page(PageSize.Letter)); document.Pages.Add(new Page(PageSize.Letter)); document.Pages.Add(new Page(PageSize.Letter)); // Create a template and add elements to it Template template = new Template(); Table2 headerTable = new Table2(0, 0, 512, 10); //Removing borders. headerTable.Border.Width = 0; headerTable.CellDefault.Border.Width = 0; Column2 heaerCol1 = headerTable.Columns.Add(170.66f); Column2 heaerCol2 = headerTable.Columns.Add(170.66f); Column2 heaerCol3 = headerTable.Columns.Add(170.66f); Row2 headerRow1 = headerTable.Rows.Add(); Cell2 headerRow1Cell1=headerRow1.Cells.Add("EmployeeId: EMP101"); headerRow1Cell1.Align = TextAlign.Left; Cell2 headerRow1Cell2=headerRow1.Cells.Add("Department Name: INV"); headerRow1Cell2.Align = TextAlign.Center; Cell2 headerRow1Cell3=headerRow1.Cells.Add("Project Code: PRJ01"); headerRow1Cell3.Align = TextAlign.Right; Row2 headerRow2 = headerTable.Rows.Add(); Cell2 headerRow2Cell1=headerRow2.Cells.Add("Employee Name: John"); headerRow2Cell1.Align = TextAlign.Left; Cell2 headerRow2Cell2=headerRow2.Cells.Add("Department Name: INVT"); headerRow2Cell2.Align = TextAlign.Center; Cell2 headerRow2Cell3=headerRow2.Cells.Add("Project Name: FMCG"); headerRow2Cell3.Align = TextAlign.Right; headerTable.Height = headerTable.GetRequiredHeight(); template.Elements.Add(headerTable); Table2 footerTable = new Table2(0, 670, 512, 10); //Removing borders. footerTable.Border.Width = 0; footerTable.CellDefault.Border.Width = 0; Column2 footerCol1 = footerTable.Columns.Add(170.66f); Column2 footerCol2 = footerTable.Columns.Add(170.66f); Column2 footerCol3 = footerTable.Columns.Add(170.66f); Row2 footerRow1 = footerTable.Rows.Add(); Cell2 footerRow1Cell1 = footerRow1.Cells.Add("Exported Date: 04/26/2021 6:01:17 AM GMT"); footerRow1Cell1.Align = TextAlign.Left; Cell2 footerRow1Cell2 = footerRow1.Cells.Add("Confidential"); footerRow1Cell2.Align = TextAlign.Center; PageNumberingLabel pageNum = new PageNumberingLabel("%%PR%%Page%%CP%% OF %%TP%%", 0, 0, 170, 30); pageNum.Align = TextAlign.Right; Cell2 footerRow1Cell3 = footerRow1.Cells.Add(pageNum); footerRow1Cell3.Align = TextAlign.Right; footerTable.Height = footerTable.GetRequiredHeight(); template.Elements.Add(footerTable); // Add the template to the document document.Template = template; // Save the PDF document string outputPath = @"C:\Temp\MyDocument.pdf"; document.Draw(outputPath); Feel free to download a fully functional evaluation edition of DynamicPDF Core Suite for .NET from NuGet(Package ID: ceTe.DynamicPDF.CoreSuite.NET) or from our website here . Thanks, ceTe Software Support Team

Re: Header Footer with multiple line with multiple alignment.

Forum member · Jul 7, 2021
Hi Team, Thanks for quick response. Your provided solution works fine. But in my case i have one more requirement. Here in below code that is provided by your team, "EmployeeId" font must be in Bold and "EMP101" should come in normal font. Just to simplify all the Key element should be in bold and all the value should be in normal font. This code is reference from your provided solution. Cell2 headerRow1Cell1=headerRow1.Cells.Add("EmployeeId: EMP101"); Thanks & Regards, Chandan Singh

Re: Header Footer with multiple line with multiple alignment.

Support · Jul 7, 2021
Hi Chandan, You can use an HtmlArea to set part of your text to bold using HTML tag and add this to the table cell. Here is a code sample: Row2 headerRow1 = headerTable.Rows.Add(); string EmployeeId="EmployeeId: "; string EMPNumber="EMP101"; string text = "<p> <b>"+EmployeeId+"</b>" + EMPNumber+"</p>"; HtmlArea area1 = new HtmlArea(text, 0, 0, 170, 20); Cell2 headerRow1Cell1 = headerRow1.Cells.Add(area1); You could also use a FormattedTextArea in a similar way. Thanks, ceTe Software Support Team

Re: Header Footer with multiple line with multiple alignment.

Forum member · Jul 9, 2021
Hi Team, Thanks for quick response. Your provided solution works fine. In header i have two rows , how to reduce spaces between 1st and 2nd row? Thanks & Regards, Chandan Singh

Re: Header Footer with multiple line with multiple alignment.

Support · Jul 9, 2021
Hi Chandan, Table row height will be decided based on the font size used to add text or height of page element (HtmlArea height) to the cell. There is no direct way to reduce the spacing between rows but you can set cell padding value to zero and see it helps. Here is a code sample. headerTable.CellDefault.Padding = 0; Thanks, ceTe Software Support Team