Convert WOFF2 to WOFF | .NET
Contents
[
Hide
]
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:
-
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);
-
Write the output setting for the
WOFF
format.// Woff output settings string outPath = Path.Combine(OutputDir, "Woff2ToWoff_out1.woff"); FileStream outStream = File.Create(outPath);
-
Convert and save the font result.
// Convert woff2 to woff font.SaveToFormat(outStream, FontSavingFormats.WOFF);
Other examples and documentation are also always available in Aspose.Font.Examples.sln solution, in the net-examples of the Aspose.Font Documentation Github repository.
Also, get to the Font Conversion application from Aspose to try the functionality.