Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="HeaderFooterInPDF/HeaderFooterInPDF.csproj" />
</Solution>
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
}
Loading