Learn how to convert TTF to WOFF using C#: https://blog.aspose.com/2022/03/15/convert-ttf-to-woff-using-csharp/
The following topics are covered in this article:
- C# TTF to WOFF Converter API
- Convert TTF to WOFF using C#
- Convert TTF to WOFF2 in C#
Learn how to convert TTF to WOFF using C#: https://blog.aspose.com/2022/03/15/convert-ttf-to-woff-using-csharp/
The following topics are covered in this article:
| // This code example demonstrates how to convert TTF to WOFF. | |
| // TTF file path | |
| string fontPath = @"D:\Files\font\Montserrat-Regular.ttf"; | |
| // Load the Font file | |
| FileSystemStreamSource source = new FileSystemStreamSource(fontPath); | |
| // Create font file definition | |
| FontFileDefinition fileDefinition = new FontFileDefinition(source); | |
| // Create font definition | |
| FontDefinition fontDefinition = new FontDefinition(FontType.TTF, fileDefinition); | |
| // Open font | |
| Font font = Font.Open(fontDefinition); | |
| // WOFF output path | |
| string outPath = @"D:\Files\font\TtfToWoff_out1.woff"; | |
| FileStream outStream = File.Create(outPath); | |
| // Convert TTF to WOFF | |
| font.SaveToFormat(outStream, FontSavingFormats.WOFF); | 
| // This code example demonstrates how to convert TTF to WOFF2. | |
| // TTF file path | |
| string fontPath = @"D:\Files\font\Montserrat-Regular.ttf"; | |
| // Load the Font file | |
| FileSystemStreamSource source = new FileSystemStreamSource(fontPath); | |
| // Create font file definition | |
| FontFileDefinition fileDefinition = new FontFileDefinition(source); | |
| // Create font definition | |
| FontDefinition fontDefinition = new FontDefinition(FontType.TTF, fileDefinition); | |
| // Open font | |
| Font font = Font.Open(fontDefinition); | |
| // WOFF output path | |
| string outPath = @"D:\Files\font\TtfToWoff_out1.woff"; | |
| FileStream outStream = File.Create(outPath); | |
| // Convert TTF to WOFF | |
| font.SaveToFormat(outStream, FontSavingFormats.WOFF2); |