Loading a true type font with GDI+
page 1 of 1
Published: 05 Dec 2003
Unedited - Community Contributed
Abstract
In this article I will show you how to use a font that is not installed on the server by loading it at run time!
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24550/ 51

Loading a true type font with GDI+

Loading a true type font with GDI+
by Chris Garrett

In this article I will show you how to use a font that is not installed on the server by loading it at run time!

The obvious immediate use for this is where you are on shared hosting or any other occasion where you can't or don't want to bother your ISP/Server Admin.

This solution is administrator-free, you only need a font and FTP :O)

See it in action
http://authors.aspalliance.com/chrisg/tools/LoadFont.aspx

View Source
- http://authors.aspalliance.com/chrisg/tools/view-LoadFont.vb.aspx
- http://authors.aspalliance.com/chrisg/tools/view-LoadFont.aspx.aspx

The way it works is to create a PrivateFontCollection()  from the System.Drawing.Text namespace. This enables us to create a collection of font families outside of the main user fonts.

To this collection we add our font file by pointing to the filesystem path of the .ttf (True Type Font).

After this is loaded we need to from then on use an instance of a font family only from this collection - the effect otherwise is the system selects a match for you so the font displayed would not be the one we loaded.

The remainder of the script deals with displaying the various combinations of style depending on if the style is available using IsStyleAvailable.

If you like the Lazy Dog font I have used it is available from http://www.neave.com/

Download
- http://authors.aspalliance.com/chrisg/tools/download.asp?file=LoadFont.aspx
- http://authors.aspalliance.com/chrisg/tools/download.asp?file=LoadFont.vb



User Comments

Title: Display Content   
Name: Imrankhan
Date: 2009-08-04 8:05:52 AM
Comment:
Hey. Is it possible to apply font style on content in web page? How do we use font style in style sheet (.css file) file if font file is not installed on the server?
Title: Great stuff   
Name: m a
Date: 2009-03-10 1:12:51 AM
Comment:
Nice. Just what I was looking for!
Title: Links have been fixed   
Name: Brendan
Date: 2007-07-26 10:03:01 AM
Comment:
Pete and Ken,
The links have now been fixed.
Enjoy.
Title: Broken Links   
Name: Ken
Date: 2007-07-25 12:52:48 AM
Comment:
still cannot download/view the source files.
Title: Broken link   
Name: Pete
Date: 2006-07-20 10:48:16 AM
Comment:
Broken link for source file.
Title: Lazy Dog font   
Name: penguinluver
Date: 2005-10-12 8:50:14 PM
Comment:
i can't seem to find the lazy dog font on neave.com.. :(

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-03-26 9:04:45 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search