diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font.slnx b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font.slnx new file mode 100644 index 00000000..bba3c45a --- /dev/null +++ b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj new file mode 100644 index 00000000..95d39578 --- /dev/null +++ b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj @@ -0,0 +1,27 @@ + + + + Exe + net10.0 + Custom_Font + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx new file mode 100644 index 00000000..201ddad8 Binary files /dev/null and b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx differ diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf new file mode 100644 index 00000000..307a18c1 Binary files /dev/null and b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf differ diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf new file mode 100644 index 00000000..277b5aeb Binary files /dev/null and b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf differ diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Output/.gitkeep b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Program.cs b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Program.cs new file mode 100644 index 00000000..71db685a --- /dev/null +++ b/Excel to PDF/Custom Font/.NET/Custom Font/Custom Font/Program.cs @@ -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 fontStreams = new List(); + + // 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); + } + } +} \ No newline at end of file diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font.slnx b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font.slnx new file mode 100644 index 00000000..bba3c45a --- /dev/null +++ b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj new file mode 100644 index 00000000..75c279a7 --- /dev/null +++ b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Custom Font.csproj @@ -0,0 +1,27 @@ + + + + Exe + net10.0 + Custom_Font + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx new file mode 100644 index 00000000..98e8c968 Binary files /dev/null and b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/Input.xlsx differ diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf new file mode 100644 index 00000000..307a18c1 Binary files /dev/null and b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/roboto.ttf differ diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf new file mode 100644 index 00000000..277b5aeb Binary files /dev/null and b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Data/MyFonts/robotob.ttf differ diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Output/.gitkeep b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Program.cs b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Program.cs new file mode 100644 index 00000000..d804fd0c --- /dev/null +++ b/Worksheet to Image/Custom Font/.NET/Custom Font/Custom Font/Program.cs @@ -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 fontStreams = new List(); + + // 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); + } + } +} \ No newline at end of file