Convert WOFF2 to WOFF | .NET

[ ]

From this article, you will find out how to convert fonts from WOFF2 to WOFF format with the help of the Aspose solution.

First, you need to add the following namespaces at the head of the file:

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

Make sure you’ve learned the conversion fundamentals in How to convert the font into the desired format? section.

Then to fulfil WOFF2 to WOFF conversion you will need to take these three steps:

  1. Open Woff2 font file.

        // 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. Write the output setting for the WOFF format.

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

  3. Convert and save the font result.

        // Convert woff2 to woff
        font.SaveToFormat(outStream, FontSavingFormats.WOFF);