Skip to content

Commit 8fc48ab

Browse files
Merge pull request #198 from SyncfusionExamples/Get-missing-fonts-for-pdf-conversion
Get-missing-fonts-for-pdf-conversion
2 parents eec710b + 75df27f commit 8fc48ab

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34622.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-missing-fonts-for-pdf-conversion", "Get-missing-fonts-for-pdf-conversion\Get-missing-fonts-for-pdf-conversion.csproj", "{00350790-253A-4C89-998B-5CA4519D6616}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{00350790-253A-4C89-998B-5CA4519D6616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{00350790-253A-4C89-998B-5CA4519D6616}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{00350790-253A-4C89-998B-5CA4519D6616}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{00350790-253A-4C89-998B-5CA4519D6616}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C3FE9097-3C04-46B1-B88C-61C71660DF48}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Get_missing_fonts_for_pdf_conversion</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+
</Project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.DocIORenderer;
4+
using Syncfusion.Pdf;
5+
6+
namespace Get_missing_fonts_for_pdf_conversion
7+
{
8+
class Program
9+
{
10+
// List to store names of fonts that are not installed
11+
static List<string> fonts = new List<string>();
12+
static void Main()
13+
{
14+
// Open the existing DOCX file stream
15+
using (FileStream docStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read))
16+
{
17+
// Load the file stream into a Word document
18+
using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Docx))
19+
{
20+
// Hook the font substitution event to detect missing fonts
21+
wordDocument.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
22+
23+
// Instantiate DocIORenderer for Word to PDF conversion
24+
using (DocIORenderer render = new DocIORenderer())
25+
{
26+
// Convert Word document into PDF document
27+
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
28+
29+
// Save the PDF document to output stream
30+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Data/Result.pdf"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
31+
{
32+
pdfDocument.Save(outputStream);
33+
}
34+
}
35+
}
36+
}
37+
38+
// Print the fonts that are not available in machine, but used in Word document.
39+
if (fonts.Count > 0)
40+
{
41+
Console.WriteLine("Fonts not available in environment:");
42+
foreach (string font in fonts)
43+
Console.WriteLine(font);
44+
}
45+
else
46+
{
47+
Console.WriteLine("Fonts used in Word document are available in environment.");
48+
}
49+
}
50+
51+
// Event handler for font substitution event
52+
static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
53+
{
54+
// Add the original font name to the list if it's not already there
55+
if (!fonts.Contains(args.OriginalFontName))
56+
fonts.Add(args.OriginalFontName);
57+
}
58+
}
59+
60+
}

0 commit comments

Comments
 (0)