Last post Apr 10, 2014 06:12 AM by IranianCuriousBoy
Apr 06, 2014 08:37 AM|IranianCuriousBoy|LINK
I'm trying to use fonts on the server that is not installed but it seems that PrivateFontCollection does not work. Here is my code:
protected void Page_Load(object sender, EventArgs e)
Image image = new Bitmap(600, 400);
Graphics g = Graphics.FromImage(image);
PrivateFontCollection fonts = new PrivateFontCollection();
fonts.AddFontFile(HttpContext.Current.Request.PhysicalApplicationPath + "\\Fonts\\NellaSueDEMO.ttf");
Font font = new Font(fonts.Families.Name, 20);
g.DrawString("Sample", font, new SolidBrush(Color.Black), 300, 200);
Response.ContentType = "image/png";
Apr 06, 2014 02:21 PM|PatriceSc|LINK
Note sure but what if you try
http://msdn.microsoft.com/en-us/library/8882dhsk(v=vs.110).aspx that is to initialize the font with a family object rather than with a family name (in the second case I don't see how it could guess it has to use the PrivateFontCollection, in the second
case, the family object does come from this collection) ? At least it would be my first try.
Edit: so I would try Font font
20); rather than
Font font =
Apr 08, 2014 12:44 AM|markfitzme|LINK
Are you receiving an error? If so, can you post it here?
If Fonts is a directory off the root of your application, try
This will return the physical path from the virtual file's path based on the root of this current application.
Apr 08, 2014 03:57 AM|IranianCuriousBoy|LINK
The documention says that name must be used and if I use Family, Visual Studio crashes. there is no error and result is displayed with default font and not with NellaSue(script font style). Originally I used a persian font and it did not work and I tested
it with a english font(NellaSue) from a website but the result was the same. I searced the PrivateFontCollection in the forum and it seems other poeple used it successfully. I think there is a point using it or there is a problem with my OS(Win 8).
Apr 08, 2014 04:30 AM|PatriceSc|LINK
http://msdn.microsoft.com/en-us/library/y505zzfw(v=vs.110).aspx with your font file. Use the same overload and it seems that they also included the style as part of the name.
Does the same work in Windows 7 ?
Apr 09, 2014 06:17 AM|IranianCuriousBoy|LINK
I used the same overload but nothing changed. They included the style as part of the name for drawing it on the form. Both my laptop and desktop have win 8 installed on them. I would be thankful if you test it on you computer.
Apr 09, 2014 07:04 AM|PatriceSc|LINK
I gave a try using a Windows app and :
PrivateFontCollection pfc = new PrivateFontCollection();
foreach (var family in pfc.Families)
var myFont = new Font(family, 18);
label1.Font = myFont;
worked for me. It didn't work when using the family name rather than a family object. What was the error you had when trying this approach ? Have you tried with other font files ? I tested with La Unica from
Apr 10, 2014 06:12 AM|IranianCuriousBoy|LINK
I checked again and this time it was Ok with Families. The day I started this thread, IIS crashed serveral times and I used name. It seems that working with fonts is unstable because in my applicatin sometimes font size changes. Thanks anyway.