Skip to content

Commit 5837d4b

Browse files
Merge pull request #235 from VijayadharshiniMathiyalagan/main
ES-871874 Modify github sample for performing font substitution of multiple fonts according to FontStyle
2 parents a0ac03a + 5ba30ac commit 5837d4b

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Word-to-PDF-Conversion/Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing/Program.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,21 @@ static void Main(string[] args)
3838
private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
3939
{
4040
//Sets the alternate font when a specified font is not installed in the production environment.
41-
if (args.OriginalFontName == "Arial Unicode MS" && args.FontStyle == FontStyle.Regular)
42-
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/Arial.TTF"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
43-
else
44-
args.AlternateFontName = "Times New Roman";
41+
if (args.OrignalFontName == "Arial Unicode MS")
42+
{
43+
switch (args.FontStyle)
44+
{
45+
case FontStyle.Italic:
46+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/Arial_italic.TTF"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
47+
break;
48+
case FontStyle.Bold:
49+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/Arial_bold.TTF"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
50+
break;
51+
default:
52+
args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/Arial.TTF"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
53+
break;
54+
}
55+
}
4556
}
4657
}
4758
}

Word-to-PDF-Conversion/Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing/Use-alternate-font-without-installing.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
<None Update="Data\Arial.TTF">
1515
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1616
</None>
17+
<None Update="Data\Arial_bold.TTF">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
<None Update="Data\Arial_italic.TTF">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
1723
<None Update="Data\Template.docx">
1824
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1925
</None>

0 commit comments

Comments
 (0)