Convert TTF to WOFF | API Solution for .NET

If you came across a font you like to use in your interface, and it is only available in TTF format, but you use WOFF in your project, you may need a solution that converts fonts. The following documentation will show you how to easily use the Aspose.Font for .NET to transform fonts from True type to WebFont.

Use the following namespaces at the head of the file:

2using Aspose.Font.Sources;
3using Aspose.Font.Ttf;
4using System;
5using System.IO;

The fundamentals for the conversion are placed in How to convert the font into the desired format? section.

To convert TTF to WOFF you will need to take the following steps:

  1. Open TTF font.

    1    // Open ttf font
    2    string fontPath = Path.Combine(DataDir, "Montserrat-Regular.ttf");
    3    FontDefinition fontDefinition = new FontDefinition(FontType.TTF, new FontFileDefinition(new FileSystemStreamSource(fontPath)));
    4    Font font = Font.Open(fontDefinition);

  2. Write the settings for the output stream.

    1    // Woff output settings
    2    string outPath = Path.Combine(OutputDir, "TtfToWoff_out1.woff");
    3    FileStream outStream = File.Create(outPath);

  3. Convert font to WOFF.

    1    // Convert ttf to woff
    2    font.SaveToFormat(outStream, FontSavingFormats.WOFF);


Here the SaveToFormat() method of the base abstract Font class instance was used. It takes two arguments: output stream and FontSavingFormats enumeration to choose output font format.

All of the code snippets provided and others are placed in the Aspose.Font.Examples.sln solution, in the net-examples folder of the Aspose.Font Documentation Github repository.

To convert fonts online you may also try a free online Font Conversion application from Aspose.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.