The Web Open Font Format or simply WOFF is a web font mostly used on web pages. In certain cases, we may need to convert Web fonts to true-type fonts. The True Type Font or TTF is used in operating systems for all digital platforms. In the previous post, we have seen how to convert TTF to web fonts. In this article, we will learn how to convert WOFF to TTF in Java.
The following topics shall be covered in this article:
Java WOFF to TTF Converter API
The FontFileDefinition class of the API represents the Font file definition. The FontDefinition class allows working with the font’s internal data such as name, type, etc. The Font.open() method opens a font, using the FontDefinition object. We can save the loaded font to other formats using the saveToFormat() method of the Font class. The save formats are provided in the FontSavingFormats enumeration.
Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-font</artifactId> <version>22.6</version> </dependency>
Convert WOFF to TTF using Java
We can easily convert Web Open Fonts (WOFF) to True Type Fonts (TTF) by following the steps given below:
- Firstly, load the font file using the FileSystemStreamSource class.
- Next, create an instance of the FontFileDefinition class with file extension as “woff” and the source file object as arguments.
- Then, initialize the FontDefinition class object with Font type as TTF and FontFileDefinition object.
- After that, open the font using the Font.open() method with the FontDefinition object as an argument.
- Finally, call the saveToFormat() method to save it. It takes the output file path and FontSavingFormats to TTF as arguments.
The following code sample demonstrates how to convert WOFF to TTF using Java.
Convert WOFF2 to TTF using Java
We can also convert WOFF2 to TTF by following the steps mentioned earlier. However, we just need to set the file extension as “woff2” in the second step.
The following code sample demonstrates how to convert WOFF2 to TTF using Java.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
In this article, we have learned how to convert Web Open Fonts to True Type Fonts in Java. We have also seen how to save WOFF2 as TTF programmatically. Besides, you can learn more about Aspose.Font for Java API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.