Skip to content

Commit 465bb59

Browse files
Added ASP.NET Core and WindowsForms samples for Get-missing-fonts-for-PDF-conversion
1 parent 213ed57 commit 465bb59

File tree

91 files changed

+75306
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+75306
-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.8.34205.153
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", "{52D17BBA-17AE-4A02-AD8D-19942B49FD1B}"
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+
{52D17BBA-17AE-4A02-AD8D-19942B49FD1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{52D17BBA-17AE-4A02-AD8D-19942B49FD1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{52D17BBA-17AE-4A02-AD8D-19942B49FD1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{52D17BBA-17AE-4A02-AD8D-19942B49FD1B}.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 = {A1EBB0FC-9BDF-4825-821A-E4FD40462895}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
5+
</startup>
6+
</configuration>

Word-to-PDF-Conversion/Get-missing-fonts-for-pdf-conversion/.NET-Framework/Get-missing-fonts-for-PDF-conversion/Form1.Designer.cs

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocToPDFConverter;
3+
using Syncfusion.OfficeChartToImageConverter;
4+
using Syncfusion.Pdf;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.ComponentModel;
8+
using System.Data;
9+
using System.Drawing;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using System.Windows.Forms;
14+
15+
namespace Get_missing_fonts_for_PDF_conversion
16+
{
17+
public partial class Form1 : Form
18+
{
19+
// List to store names of fonts that are not installed
20+
static List<string> fonts = new List<string>();
21+
public Form1()
22+
{
23+
InitializeComponent();
24+
}
25+
26+
private void browseButton_Click(object sender, EventArgs e)
27+
{
28+
openFileDialog1.InitialDirectory = Application.StartupPath + @"..\..\Data\DocIO\";
29+
openFileDialog1.FileName = "";
30+
DialogResult result = openFileDialog1.ShowDialog();
31+
32+
if (result == DialogResult.OK)
33+
{
34+
this.textBox1.Text = openFileDialog1.SafeFileName;
35+
this.textBox1.Tag = openFileDialog1.FileName;
36+
}
37+
}
38+
39+
private void btnconvert_Click_1(object sender, EventArgs e)
40+
{
41+
if (this.textBox1.Text != String.Empty)
42+
{
43+
WordDocument wordDoc = new WordDocument((string)textBox1.Tag, Syncfusion.DocIO.FormatType.Automatic);
44+
//Initialize chart to image converter for converting charts in word to pdf conversion
45+
wordDoc.ChartToImageConverter = new ChartToImageConverter();
46+
wordDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Normal;
47+
DocToPDFConverter converter = new DocToPDFConverter();
48+
49+
// Hook the font substitution event to detect missing fonts
50+
wordDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
51+
//Convert word document into PDF document
52+
PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc);
53+
//Save the pdf file
54+
pdfDoc.Save("DoctoPDF.pdf");
55+
56+
// Print the fonts that are not available in machine, but used in Word document.
57+
if (fonts.Count > 0)
58+
{
59+
string misddedFonts = string.Empty;
60+
Console.WriteLine("Fonts not available in environment:");
61+
int i = 0;
62+
foreach (string font in fonts)
63+
{
64+
misddedFonts += '\n' + font;
65+
i++;
66+
67+
}
68+
MessageBox.Show("Fonts not available in environment:" + misddedFonts);
69+
}
70+
else
71+
{
72+
MessageBox.Show("Fonts used in Word document are available in environment.");
73+
}
74+
//Message box confirmation to view the created document.
75+
if (MessageBox.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
76+
{
77+
try
78+
{
79+
System.Diagnostics.Process.Start("DoctoPDF.pdf");
80+
//Exit
81+
this.Close();
82+
}
83+
catch (Exception ex)
84+
{
85+
Console.WriteLine(ex.ToString());
86+
}
87+
}
88+
}
89+
else
90+
{
91+
MessageBox.Show("Browse a word document and click the button to convert as a PDF.");
92+
}
93+
}
94+
95+
// Event handler for font substitution event
96+
static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
97+
{
98+
// Add the original font name to the list if it's not already there
99+
if (!fonts.Contains(args.OriginalFontName))
100+
fonts.Add(args.OriginalFontName);
101+
}
102+
103+
private void Form1_Load(object sender, EventArgs e)
104+
{
105+
this.textBox1.Text = "Input.docx";
106+
this.textBox1.Tag = Application.StartupPath + @"..\..\..\Data\Input.docx";
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)