Convert WOFF2 to TTF | .NET

[ ]

This page is aimed to show how to convert fonts from Web Open Font Format 2 to True Type font using the Aspose.Font for .NET.

Set the following namespaces at the head of the file:

using Aspose.Font.Sources;
using Aspose.Font.Ttf;
using System;
using System.IO;

How to convert the font into the desired format? chapter will let you know about the Aspose conversion fundamentals.

To convert WOFF2 to TTF make the next actions:

  1. Open Woff2 font.

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

  2. Add the output setting.

        // Ttf output settings
        string outPath = Path.Combine(OutputDir, "Woff2ToTtf_out1.ttf");
        FileStream outStream = File.Create(outPath);

  3. Convert font and save the result.

        // Convert woff2 to ttf
        font.SaveToFormat(outStream, FontSavingFormats.TTF);