Reputation: 439
I would like to extend truetype font located in traditional MS Windows font pack with additional symbol and generate new pdf document using it. Is it possible?
Upvotes: 1
Views: 1333
Reputation: 439
Design custom TrueType font using built-in EUDC editor (Windows)
You may use any font editor capable of handling TrueType or OpenType fonts, and the most simplistic and available is end user character editor provided by Microsoft and shipped with Windows. It’s called eudcedit and one may run it by executing the eudcedit command in Run window (can be invoked by pressing Windows Key + R).The editor starts and you can now design your own characters using its graphical tools and also define their codes. When you’re done with characters design you may then save them by choosing File -> Font Links… and pressing OK in invoked dialog.
From now on, these end user defined characters can be used by many text editing and viewing applications if they implement the EUDC support. If they use Windows API for displaying text it will work automatically.
We are going to design a few simple characters, and use the resulting font in PDF generation routine. See the image below showing the character editor window, code assigning and font saving process.
The assigned character code was highlighted on the preceding image, we used the one assigned by default but it’s possible to use any of the allowed codes. We can use the designed and saved character and create a PDF file containing it. For it to work let’s copy the resulting font from windows fonts directory and rename the resulting file by changing its extension from tte to ttf.
Assuming that OS is installed at “C:\Windows” and we are going to copy the file to “C:\customfonts\eudc.ttf” it looks as follows (using command prompt).The following code produces PDF file containing the characters we created (using API of Apitron.PDF.Kit for .NET):
// create document
FlowDocument document = new FlowDocument() { Margin = new Thickness(5) };
// lets create the village, using \uE000 charcode for each symbol
document.Add(new TextBlock("\uE000\uE000\uE000\uE000\uE000\uE000\uE000\uE000")
{ Font = new Font(@"c:\customfonts\eudc.ttf", 20) });
// generate PDF document
using (Stream stream = File.Create("CustomFontsUsageSample.pdf"))
{
document.Write(stream, new ResourceManager(), new PageBoundary(Boundaries.A4));
}
The image below demonstrates the result:
Furthermore, this custom font will be embedded into the resulting document making it viewable on other devices which obviously don’t have our custom font installed.
Upvotes: 2