Fonts can be installed into the client's machine through c#.
First everyone tries to copy the file to the "C:\Windows\Fonts"(assuming OS is installed on C drive).And gets a flower kept in the ears.Ya.Actually, An application can use a font to draw text only if that font is either resident on a specified device or installed in the system font table.
The font table is an internal array that identifies all nondevice fonts that are available to an application.A method exists to access this table.
Now let us see the code:
using System;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.IO;
using System.Runtime.InteropServices;
public partial class Class_Name : System.Web.UI.Page
{
[DllImport("gdi32")]
public static extern int AddFontResource(string lpFileName);
protected void Page_Load(object sender, EventArgs e)
{
File.Copy(Server.MapPath("mfdev010.ttf"), "C:\\Windows\\fonts\\mfdev010.ttf");
// Adding the font ..
AddFontResource("mfdev010.ttf");
Response.Write("Installation successful");
}
}
Explanation:
Here what i have done is
1.Put the font file in the application directory.
2.First copy the font file to the windows(font location).Be careful to check.some machines may have OS installed in other drives other than C drive.
3.Add the font to the font resource file by using the "AddFontResource" method.However,in order to use this function,you need to write an api(as shown above) using gdi32 dll.
Now as you start debugging,as page loads font gets installed.
Have nice coding!!!
Bye.
No comments:
Post a Comment