views:

194

answers:

3

Hi,

I am trying to convert text into graphics using c#.

My input is character string and output is bitmap with the input text.

After lot of search I found some ways to do it, I found some techiques which uses this kind of techinque. For Example While creating Captcha, we have to print the character in the bitmap.

But for that I should have the font installed in my windows.

I can not perform such operation without installing the font.

I have .ttf file with me but I dont want to install it because my work for that font is temporary only.

Is there any way where I can extract out the Font's graphical information by providing the Character?

I have also found font parser code http://swinglabs.java.sun.com/hudson/job/PDFRenderer%20Weekly%20Build/javadoc/com/sun/pdfview/font/package-summary.html

Can anyone please provide me how to develpo similar thing using c#.Net?

Or

From where can I get the algorithm to parce font?

A: 

Hi!

You can use the PrivateFontCollection Class to use fonts that are not installed in Windows.

No need to parse them yourself.

PDFsharp Team
A: 

Hello PDFsharp Team,

Thanks a lot for your suggestion. Sorry for late reply but I was on leave for few days.

I have started creating small proof of concept application using PrivateFontCollection and I am planning to test the application with some sample font files.

I would also share my results with community.

Regards

HBA
A: 

Hello,

I have created small proof of concept application with following simple code to show the text on Label control.

PrivateFontCollection pfc = new PrivateFontCollection(); string fontFilePath = @"C:\TestFonts\Font1.TTF"; pfc.AddFontFile(fontFilePath); Font font = new Font(pfc.Families[0], 30, FontStyle.Bold); label1.Text = "ABCEDGHHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwzyz"; label1.Font = font;

After some test I found that the above code is not working with some ttf files. It was throwing an exception “File not found” even files were present and paths were correct.

Then I realize that the files have different icon. They have “O” instead of “T” as file icon. Later I did some search and found that those files are Opentype font files and PrivateFontCollection does not work with Open type files with post script out line. Honestly speaking I did not understand much here :(. Still I searched more and found some links (search with key word “online font converter”) http://search.yahoo.com/search;_ylt=A0geu.HihaRLIOsAgtVXNyoA?p=online+font+converter&fr2=sb-top&sao=0

I opened one and provided my test open type ttf file to it and the site has converted it to normal ttf files and they worked with PrivateFontCollection.

Is there any work around to work with PrivateFontCollection for open type ttf files.

I am also curious to know how the sites provided in above links convert the font file types.

Can I convert my files like those sites convert inside my application? If I can do it then with the help of PrivateFontCollection I would be able to solve my problem.

Please bear with my ignorance.

Regards

HBA