Font converter | API Solution for Java

Overview

Creating interfaces would be much easier if there was only one universal font format. However, due to the multitude of gadgets, environments, operating systems, and various applications where fonts are used, we have a plethora of font formats tailored to specific needs. Each font format has its advantages and disadvantages, with some optimized for web pages and applications, while others are more suitable for publishing. To ensure optimal rendering across different platforms, it may be necessary to convert fonts from one format to another.

For some tasks, a web application will be just enough. For example, if you only need to convert one text document into a document with a different font type. And Aspose does have such an application in its ecosystem. Try Font Conversion application to see whether it fits your purposes.

If your needs extend beyond what a web application can provide and you require a more robust solution to integrate into your product, consider utilizing this tool designed to streamline the font conversion process for you. Aspose.Font for Java library is a powerful solution that facilitates the conversion of fonts between various popular formats:

It is a flexible and easy-to-use library designed to work with different font files like TrueType CFF, OpenType, and Type1. In addition to font conversion capabilities, it also provides various other font manipulations, such as retrieving font details, accessing glyph and metrics data, identifying Latin characters, and loading fonts, among others.

Supported font formats

The next formats are supported by Aspose.Font for Java:

FormatDescription
TrueType (TTF)It is one of the most popular formats between Mac Os and Microsoft Windows operating systems. True type fonts have .ttf extension. Fonts of the TrueType family are easy to scale to any size on computers and other devices like printers, smartphones, etc. The most famous representatives of TTF fonts are Times Roman, Helvetica, and Courier families.
Web Open Font Format (WOFF)This font format is developed for rendering on web pages. Basically, it is TrueType or OpenType font altered by adding HTML metadata and by applied compression. The format is supported by all major browsers.
Web Open Font Format version 2.0 (WOFF2)The next generation of WOFF. It gives you a 30% average compression gain in comparison to WOFF. It is not that widespread though yet.
Embedded OpenType format (EOT)These are made by Microsoft and supported by Internet explorer fonts used on the web. Because of compression, the font files are smaller. EOT also provides some copyright protection because of subsetting.
Type 1 format(also known as PostScript, PS1, T1, Adobe Type 1, Multiple Master, or MM). This format is developed by Adobe Systems for professional digital typesetting. This system uses the PostScript file format to encode font information. As this font format is outdated and is not supported in many modern environments, like mobile devices and web browsers, it will not have been supported by Adobe by 2023 anymore. The company recommends using the Open type format instead.
Compact Font Format (CFF)It is also known as Type 2 font format, or CFF/Type 2 font format. With this format, you can store different fonts together in one unit called Fontset. As it allows sharing data between fonts, and defaulting frequently occurring data it provides you with notable space saving.
Scalable Vector Graphics (SVG)SVG is a file format used to display vector-based graphics and images on the web. SVG fonts, also known as SVG-in-OpenType or SVGOT fonts, are a specific type of font format within SVG. Each character in an SVG font is defined as a separate SVG path or shape so SVG fonts can be scaled without losing quality.

All of the mentioned formats are supported for reading, and some of them for writing.

Formats supported for reading and/or writing

FormatReadWrite
TTFticktick
CFFtick
WOFFticktick
WOFF2ticktick
Type 1tick
EOTtick
SVGtick

Available font conversions

Any font format from those supported for reading can be converted and saved into one of the formats supported for writing.

Here you can learn the pairs of fonts which are currently provided for conversion by the Aspose solution. Following the links, you will find more information and examples of using the library illustrated with the code snippets.

How to convert the font into the desired format?

  1. Load font from any of the supported formats and get reference on base com.aspose.font.Font object which represents this font.
  2. Save just loaded font into another format with the help of saveToFormat() method of the base abstract Font class instance. saveToFormat() method takes two arguments: output stream and FontSavingFormats enumeration for choosing the output font format. Method saveToFormat() allows you to save fonts into any of the output formats supported.

You need to use the next statements:

 1 
 2    package com.aspose.font;
 3
 4    import java.io.FileOutputStream;
 5    import java.io.IOException;
 6    import java.nio.file.Files;
 7    import java.nio.file.Paths;
 8
 9    import com.aspose.font.ByteContentStreamSource;
10    import com.aspose.font.FileSystemStreamSource;
11    import com.aspose.font.Font;
12    import com.aspose.font.FontDefinition;
13    import com.aspose.font.FontFileDefinition;
14    import com.aspose.font.FontSavingFormats;
15    import com.aspose.font.FontType;
16    import com.aspose.font.TtfFont;

Below you can see the code sample which converts font from TTF to WOFF format.

There were taken the next steps:

  1. Opened TTF font.
  2. Added the output settings.
  3. Fulfilled the conversion TTF to WOFF and saved the resultant.
 1    // Open ttf font
 2    String fontPath = Paths.get(getDataDir(), "Montserrat-Regular.ttf").toString();
 3    FontDefinition fontDefinition = new FontDefinition(FontType.TTF, new FontFileDefinition(new FileSystemStreamSource(fontPath)));
 4    Font font = Font.open(fontDefinition);
 5
 6    // Woff output settings
 7    String outPath = Paths.get(getOutputDir(), "TtfToWoff_out1.woff").toString();
 8    FileOutputStream outStream = new FileOutputStream(outPath);   
 9
10    // Convert ttf to woff
11    font.saveToFormat(outStream, FontSavingFormats.WOFF);

Conversions into other formats, like woff to ttf, ttf to woff2, woff2 to ttf, and others can be accomplished in a similar way.

How to get the solution?

If you are interested in getting the library, go to Aspose.Font for Java product page. There you will find more opportunities that the solution gives to you. You can download a free trial from or buy the product there.

If you have any troubles or questions left, feel free to post them at the Aspose.Font.Product Family section of the Free Support Forum and within a few hours our support team will clear everything up for you.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.