Convert WOFF2 to TTF | Java

Contents
[ ]

This page is aimed to show how to convert fonts from Web Open Font Format 2 to True Type font using the Aspose.Font for Java


Use the following statements:

 
    package com.aspose.font;

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Paths;

    import com.aspose.font.ByteContentStreamSource;
    import com.aspose.font.FileSystemStreamSource;
    import com.aspose.font.Font;
    import com.aspose.font.FontDefinition;
    import com.aspose.font.FontFileDefinition;
    import com.aspose.font.FontSavingFormats;
    import com.aspose.font.FontType;
    import com.aspose.font.TtfFont;

How to convert the font into the desired format? chapter will let you know about the Aspose conversion fundamentals.

To convert WOFF2 to TTF make the next actions:

  1. Open Woff2 font.

     
        // 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. Add the output setting.

     
        // Ttf output settings
        string outPath = Path.Combine(OutputDir, "Woff2ToTtf_out1.ttf");
        FileStream outStream = File.Create(outPath);

  3. Convert font and save the result.

     
        // Convert woff2 to ttf
        font.SaveToFormat(outStream, FontSavingFormats.TTF);