Save updated font files to disc

.NET API Solution to save previously loaded from stream fonts.

 

Aspose.Font API Solution has a rich functionality to work with fonts. Conversion, manipulations with glyphs, detection of Latin symbols, loading fonts, and many more.

The next snippet describes the process of saving the font, which was originally loaded from byte array/MemoryStream, to disk. The loading itself was previously described with the code examples on the How to load fonts from a stream page.

This page describes the option on how to save TrueType font to disk but all the rest code snippets on how to use the solution are placed in the Aspose.Font-Documentation GitHub project.

To save font files we need:

  • Aspose.Font for .NET API which is a feature-rich, powerful and easy-to-use document manipulation and conversion API for C# platform.

  • Open the NuGet package manager, and search for Aspose.Font and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Font

Steps to save the before-changed font using C#:

  1. Load the font from the byte array by passing the appropriate FontDefinition to the Aspose.Font.Font.Open() Method.
  2. Read data from the just loaded TtfFont object.
  3. To save TTF Font to the disk declare the output Font file name with full path. To finish the process use the Save() Method.

C# Code for saving TrueType font to the disk

    using Aspose.Font;
    using Aspose.Font.Sources;
    using Aspose.Font.Ttf;
    //byte array to load Font from
    byte[] fontMemoryData;

    FontDefinition fd = FontDefinition.Open(new ByteContentStreamSource(fontMemoryData),
                FontType.TTF);
    TtfFont font = Aspose.Font.Font.Open(fd) as TtfFont;

    //Read some data from just loaded TtfFont object

    //Save TtfFont to disk
    //Output Font file name with the full path
    string fileName; 

    font.Save(fileName);



FAQ

1. How do I save fonts to my hard drive?

When you downloaded a font and want to save it to your drive you need to paste its file to the Fonts folder, for example, C:>Windows>Fonts if the operating system is Windows.

2. Can I copy fonts from one computer to another?

If the device you want to transfer your font to has the same operating system you can just copy and paste the font file from/to the Font folder. If the operating system or app is different, you need to convert the font to the format that is supported by such a device or environment.

3. How to save changed fonts?

To save the font to the disc, first, declare the output font file name with the full path. Then use the Save() Method.