Roshana
Roshana

Reputation: 428

How to use custom font asp.net application

How to use custom font asp.net application.
I have a font file with me. I want to add that file as a resource and use it inside the project. how to do it?

        PrivateFontCollection pfc = new PrivateFontCollection();
        Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(Server.MapPath("~/Resources/EAN-13.ttf"));

        byte[] fontdata = new byte[fontStream.Length];
        fontStream.Read(fontdata, 0, (int)fontStream.Length);
        fontStream.Close();

        unsafe
        {
            fixed (byte* pFontData = fontdata)
            {
                pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
            }
        }

I tried this. But its not working.

Upvotes: 0

Views: 2285

Answers (1)

Aristos
Aristos

Reputation: 66641

You must distinguish between the code that run on server and the code that run on client browser.

The fonts that you have on your computer, on your server, can not be visible on user computer using the code behind just because you loading the fonts.

So you have two options here.

  1. Load the fonts, and render a text in an image using this fonts, then show this image to the user.

  2. Use client side techniques to show this fonts. Some of them are cross browser font embedding, and other can be javascript that can rendered them on client side.

You can google it with "embed custom fonts website".

Also you can check : http://typeface.neocracy.org/
and Is it possible to use custom fonts - using font-face?

Upvotes: 1

Related Questions