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
3 changes: 3 additions & 0 deletions Excel to PDF/Custom Font/.NET/Custom Font/Custom Font.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Custom Font/Custom Font.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Custom_Font</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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

</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
57 changes: 57 additions & 0 deletions Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Syncfusion.XlsIO;
using Syncfusion.Drawing.Fonts;
using Syncfusion.XlsIORenderer;
using Syncfusion.Pdf;

namespace Custom_Font
{
class Program
{
static void Main(string[] args)
{
// Create a collection to store the custom font streams
List<Stream> fontStreams = new List<Stream>();

// Retrieve all font files from the specified directory
foreach (string file in Directory.GetFiles(Path.GetFullPath(@"Data/MyFonts")))
{
string extension = Path.GetExtension(file);

// Load only TrueType and OpenType font files
if (extension.Equals(".ttf", StringComparison.OrdinalIgnoreCase) ||
extension.Equals(".otf", StringComparison.OrdinalIgnoreCase))
{
// Read the font file and copy its content to a memory stream
FileStream fileStream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read);
Stream stream = new MemoryStream();
fileStream.CopyTo(stream);
stream.Position = 0;
fontStreams.Add(stream);
}
}

// Register the custom fonts for use during Excel-to-PDF conversion
FontManager.RegisterFonts(fontStreams);

using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));

XlsIORenderer renderer = new XlsIORenderer();

PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);

pdfDocument.Save(Path.GetFullPath("Output/WorkbookToPDF.pdf"));

pdfDocument.Close();
workbook.Close();
}

// Clear the registered fonts and dispose their associated streams
FontManager.ClearRegisteredFonts(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Custom Font/Custom Font.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Custom_Font</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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

</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Syncfusion.XlsIO;
using Syncfusion.Drawing.Fonts;
using Syncfusion.XlsIORenderer;

namespace Custom_Font
{
class Program
{
static void Main(string[] args)
{
// Create a collection to store the custom font streams
List<Stream> fontStreams = new List<Stream>();

// Retrieve all font files from the specified directory
foreach (string file in Directory.GetFiles(Path.GetFullPath(@"Data/MyFonts")))
{
string extension = Path.GetExtension(file);

// Load only TrueType and OpenType font files
if (extension.Equals(".ttf", StringComparison.OrdinalIgnoreCase) ||
extension.Equals(".otf", StringComparison.OrdinalIgnoreCase))
{
// Read the font file and copy its content to a memory stream
FileStream fileStream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read);
Stream stream = new MemoryStream();
fileStream.CopyTo(stream);
stream.Position = 0;
fontStreams.Add(stream);
}
}

// Register the custom fonts for use during Excel-to-Image conversion
FontManager.RegisterFonts(fontStreams);

using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
IWorksheet sheet = workbook.Worksheets[0];

application.XlsIORenderer = new XlsIORenderer();

using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Image.png"), FileMode.Create, FileAccess.Write))
{
sheet.ConvertToImage(sheet.UsedRange, outputStream);
}
}

// Clear the registered fonts and dispose their associated streams
FontManager.ClearRegisteredFonts(true);
}
}
}
Loading