diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF.slnx b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF.slnx new file mode 100644 index 00000000..4fa82301 --- /dev/null +++ b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/InputTemplate.xlsx b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/InputTemplate.xlsx new file mode 100644 index 00000000..8e3cc3ae Binary files /dev/null and b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/InputTemplate.xlsx differ diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/Syncfusion.png b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/Syncfusion.png new file mode 100644 index 00000000..4ca159ff Binary files /dev/null and b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Data/Syncfusion.png differ diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/HeaderFooterInPDF.csproj b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/HeaderFooterInPDF.csproj new file mode 100644 index 00000000..272caa79 --- /dev/null +++ b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/HeaderFooterInPDF.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Output/.gitkeep b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Program.cs b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Program.cs new file mode 100644 index 00000000..c7a19b5c --- /dev/null +++ b/Excel to PDF/HeaderFooterInPDF/.NET/HeaderFooterInPDF/HeaderFooterInPDF/Program.cs @@ -0,0 +1,42 @@ +using Syncfusion.Pdf; +using Syncfusion.XlsIO; +using Syncfusion.XlsIORenderer; +using Syncfusion.Drawing; +using System.Drawing; + +class Program +{ + static void Main(string[] args) + { + //Initialize Excel Engine + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + //Load the existing Excel document + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data\InputTemplate.xlsx")); + + Image headerImage = Image.FromStream(File.OpenRead(Path.GetFullPath(@"Data\Syncfusion.png"))); + foreach (IWorksheet sheet in workbook.Worksheets) + { + // IMPORTANT: put the image placeholder in the header/footer text + sheet.PageSetup.CenterHeader = "&G"; + sheet.PageSetup.CenterFooter = "&G"; + + // then assign the Image object + sheet.PageSetup.CenterHeaderImage = headerImage; + sheet.PageSetup.CenterFooterImage = headerImage; + } + + XlsIORenderer renderer = new XlsIORenderer(); + XlsIORendererSettings rendererSettings = new XlsIORendererSettings(); + rendererSettings.HeaderFooterOption.ShowHeader = true; + rendererSettings.HeaderFooterOption.ShowFooter = true; + + + using (PdfDocument tempDoc = renderer.ConvertToPDF(workbook, rendererSettings)) + { + tempDoc.Save(Path.GetFullPath(@"Output\ConvertedDocument.pdf")); + } + } + } +}