Load, Extract Data and Save from TTF | Java
Contents
[
Hide
Show
]Load TrueType Font from Disc
Aspose.Font for Java 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
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
2String fileName = Utils.getDataDir() + "Montserrat-Regular.ttf"; //Font file name with full path
3
4 FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
5 TtfFont font = (TtfFont) Font.open(fd);
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 Java 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-Java
2byte[] fontMemoryData = Utils.getInputFileBytes("Montserrat-Regular.ttf"); //Font file name with full path
3
4 FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new ByteContentStreamSource(fontMemoryData)));
5 TtfFont font = (TtfFont) Font.open(fd);
6
7 //Work with data from just loaded TtfFont object
8
9 //Save TtfFont to disk
10 //Output Font file name with full path
11 String outputFile = Utils.getDataDir() + "Montserrat-Regular_out.ttf";
12
13 font.save(outputFile);
To learn 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.