Skip to content

Commit 296a9bc

Browse files
Merge pull request #485 from SyncfusionExamples/995109-Update-DocIO-FallBack-Symbol-Sample
995109 - Add fallback symbol sample in DocIO
2 parents 8d56982 + 56eee51 commit 296a9bc

File tree

10 files changed

+123
-0
lines changed

10 files changed

+123
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Fallback-symbols-based-on-scripttype/Fallback-symbols-based-on-scripttype.csproj" />
3+
</Solution>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Fallback_symbols_based_on_scripttype</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIORenderer;
3+
using Syncfusion.Office;
4+
5+
namespace Fallback_symbols_based_on_scripttype
6+
{
7+
internal class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Opens the file as stream.
12+
using FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read);
13+
//Loads an existing Word document file stream.
14+
using WordDocument wordDocument = new WordDocument(inputStream, Syncfusion.DocIO.FormatType.Docx);
15+
//Adds fallback font for basic symbols like bullet characters.
16+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings");
17+
//Adds fallback font for mathematics symbols.
18+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS");
19+
//Adds fallback font for emojis.
20+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS");
21+
//Instantiation of DocIORenderer for Word to image conversion.
22+
using DocIORenderer render = new DocIORenderer();
23+
//Convert the entire Word document to images.
24+
Stream[] imageStreams = wordDocument.RenderAsImages();
25+
int i = 0;
26+
foreach (Stream stream in imageStreams)
27+
{
28+
//Reset the stream position.
29+
stream.Position = 0;
30+
//Save the stream as file.
31+
using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"../../../Output/Output_" + i + ".jpeg"));
32+
stream.CopyTo(fileStreamOutput);
33+
i++;
34+
}
35+
}
36+
}
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Fallback-symbols-based-on-scripttype/Fallback-symbols-based-on-scripttype.csproj" />
3+
</Solution>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Fallback_symbols_based_on_scripttype</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIORenderer;
3+
using Syncfusion.Pdf;
4+
using Syncfusion.Office;
5+
namespace Fallback_symbols_based_on_scripttype
6+
{
7+
internal class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Opens the file as stream.
12+
using FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read);
13+
//Loads an existing Word document file stream.
14+
using WordDocument wordDocument = new WordDocument(inputStream, Syncfusion.DocIO.FormatType.Docx);
15+
//Adds fallback font for basic symbols like bullet characters.
16+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings");
17+
//Adds fallback font for mathematics symbols.
18+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS");
19+
//Adds fallback font for emojis.
20+
wordDocument.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS");
21+
//Instantiation of DocIORenderer for Word to PDF conversion.
22+
using DocIORenderer render = new DocIORenderer();
23+
//Converts Word document into PDF document.
24+
using PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
25+
//Saves the PDF file to file system.
26+
using FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Output/Output.pdf"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
27+
pdfDocument.Save(outputStream);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)