0

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.

1
  • You want to apply this fonts to your controls? Are these downloaded from the internet? Commented Sep 16, 2012 at 11:02

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.