How does ASP. net use non-system default font on the server side?

Source: Internet
Author: User

When you do a verification code or logo watermark, you sometimes want to use some special fonts... however, it is very difficult for us to use a VM to ask the server provider to install one or more fonts on the server ....

So I had to find the answer on csdn .. however, if a good solution cannot be found for a long time, I had to myself on msdn. search for information related to font, one by one .... finally, let me find a keyword addfontfile (stringFilename), a bright spot.Privatefontcollection class, finally found the solution...

Privatefontcollection class:Provides a font family set based on client applications.ProgramProvided font file generation.

That is to say, this is a set. We only need to add our own font to this set and then call it. The following is the method to call.

Call Method

System. Drawing. Text. privatefontcollection PFC =   New System. Drawing. Text. privatefontcollection ();
String Fontpath = Server. mappath ( " ~ /Fonts/mytholog. TTF " ); // Font file path relative to the virtual directory
PFC. addfontfile (fontpath );
Font font =   New System. Drawing. Font (PFC. Families [ 0 ], 20 ); // Now we can use the font ~~

 

URL: http://blog.csdn.net/conanlwl/archive/2007/10/11/1820812.aspx

----------------------------------------

After actual use, no problem at all

This is very helpful for generating text images on the server. Thanks to the original author for sharing them.

New questions:

After one website migration, you cannot use a Custom font, and no error is reported. No reason is found.
After testing, it is found that the Font File Uploaded by FTP is damaged, and the file upload mode is changed to normal.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.