Load, Extract Data and Save from TTF | .NET
Load TrueType Font from Disc
Aspose.Font for .NET API lets you read TrueType Font types from files stored in your digital storage. TrueType font files stored on disc can be loaded by using the following steps.
- Define a new object of FontDefinition class
- Specify FontType as TTF and FontFileDefinition as ttf
- Create a TtfFont object and open the font file from FontDefinition object defined in the earlier step
The loading functionality is fully described in a separate paragraph called How to load fonts.
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
2string fileName= dataDir + "Montserrat-Regular.ttf"; //Font file name with full path
3
4FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
5TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont;
Save TTF Font
Once you load a TTF file, you may work with the font file, update some parameters and would like to save the file to disc. Aspose.Font for .NET lets you save TTF file to disc using the following steps.
- Define a new object of FontDefinition class
- Specify FontType as TTF and FontFileDefinition as ttf
- Create a TtfFont object and open the font file from FontDefinition object defined in the earlier step
- Make the required updates and save the updated Font file to disc using the TtfFont’s Save method
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
2//byte array to load Font from
3string dataDir = RunExamples.GetDataDir_Data();
4
5byte[] fontMemoryData = File.ReadAllBytes(dataDir + "Montserrat-Regular.ttf");
6FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new ByteContentStreamSource(fontMemoryData)));
7TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont;
8
9//Work with data from just loaded TtfFont object
10
11//Save TtfFont to disk
12//Output Font file name with full path
13string outputFile = RunExamples.GetDataDir_Data() + "Montserrat-Regular_out.ttf";
14
15ttfFont.Save(outputFile);
For more examples go to Aspose.Font.Examples.sln solution, in the net-examples folder of the Aspose.Font Documentation Github repository.
Also, check our free online Font Manipulation Applications to see how the functionality can be implemented in a web solution.