Hi,
I am developing an ASP .NET website that needs to create images using a custom font. Obviously, to do this, I need the font installed on the web server. As I am using a hosting site, and I have no direct access to the server the site will be hosted on, I need a script that will install the font on the server.
I have found the following solution online that uses the Windows API and theoretically should install the font:
...
using System.Runtime.InteropServices;
...
public partial class InstallFont : System.Web.UI.Page
{
[DllImport("gdi32", EntryPoint = "AddFontResource")]
public static extern int AddFontResourceA(string lpFileName);
protected void Page_Load(object sender, EventArgs e)
{
...
int result = -1;
result = AddFontResourceA(@"C:\ExampleFont.TTF");
Response.Write((result == 0) ? "Font is already installed." :
"Font installed successfully.");
}
}
This runs like a charm and tells me that the font has been installed, however, when I try to create a Font object with the font that was supposedly just installed, it does not work.
I am sure that AddFontResource is working though because when I check Microsoft Word (for testing purposes) the font shows up in its list of fonts present on the machine.
Does anyone know why .NET's font object is not recognizing the font when it has been installed and is available to other programs? It may be possible that I might have to add a registry value, but I know virtually nothing about doing that.
Any help is greatly, greatly appreciated.