Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 7, 2023 02:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/6e2885e59eeebe9c0d0a5f6d88403e8e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6e2885e59eeebe9c0d0a5f6d88403e8e to your computer and use it in GitHub Desktop.
Convert TTF to WOFF using C#
// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment