FLEXCEL STUDIO FOR .NET
7 | Page
We could have used unmanaged code to call GetFontData on the Win32 API and get the
actual data. This option was discarded because we want FlexCel to remain 100% managed.
Staying 100% managed allows it to run on 64 bits, mono and everywhere, and it made no
sense to go unmanaged just for one missing method.
We could read the font files (*.ttf) directly. This option is better, but is not perfect either. The
problem here is that the .NET framework gives the standard folder for lots of system folders,
but not for the fonts folder. Again, to access the system fonts folder (where *.ttf are) we
would need to go unmanaged.
As going unmanaged is out of question (for us), we adopted a compromise solution. We use solution
2) and assume fonts are on the
<System Folder>\..\Fonts (On Windows). This is true for all installations of Windows we are
aware of, but it might not be true for some or in the future, or in mono and Unix.
If <System Folder> is empty, then we assume we are running on Linux, and we will try
If this folder does not exist, FlexCel will search on “<folder where FlexCel.dll is>/Fonts”. If you
are running Linux, you might create a symbolic link to the place where the fonts are installed. (see
the MONO section below for more information)
As a last resort, FlexCel provides a OnGetFontFolder event that allows you to specify where fonts
are stored on your system. Here you can tell FlexCel where the fonts are.
Avoid using this event if you can, since when you use it your code will not
transparently run on MONO and Windows, you will have to have two different
binaries. A Symbolic link from the FlexCel installation folder to the fonts folder should
be a more elegant solution.
Of course, you will not face any of these problems when using only standard PDF
fonts (and no Unicode)
By the way, note that we said going unmanaged is out of question for us. If your application already
uses unmanaged code, you can use the GetFontData event on FlexCelPdfExport to call GetFontData
on the Win32 API, and return the font information to FlexCel. This way you will avoid scanning the
font folder completely, and it can speed up a little PDF export.
While we do not recommend that you go unmanaged for this since scanning the font folder is fast
anyway, you have all options. Do what you prefer.
For a demo on using the GetFontData event, see the ExportPdf demo.