Convert WOFF to WOFF2 | .NET

[ ]

If you need to transform Web OpenFont Format to its version 2.0, this article provides you with the necessary information.

Fill the head of the file with the following namespaces:

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

If you want to learn the Aspose conversion fundamentals go to How to convert the font into the desired format? chapter to find them out.

Taking the next three steps you will convert WOFF to WOFF2:

  1. Open Woff font file.

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

  2. Notify the output setting.

        // Woff2 output settings
        string outPath = Path.Combine(OutputDir, "WoffToWoff2_out1.woff2");
        FileStream outStream = File.Create(outPath);

  3. Transform the font into WOFF2 format and save the result.

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