Convert Type1 | API Solution for .NET
In this article, you will see how to convert Type 1
format. Aspose.Font for .NET offers you solutions for conversion Type 1
to TTF
, Type 1
to WOFF
, and Type 1
to WOFF2
.
For all three conversions you need to put the next namespaces at the top of the head of the title:
1
2using Aspose.Font.Sources;
3using System;
4using System.IO;
Reach How to convert the font into the desired format? chapter to see about the Aspose conversion fundamentals.
Convert Type1 to TTF
Fulfill the actions written below to tranform Type one
to True Type Font
:
- Open
Type1
font. - Apply the output settings for the
Type1
font. - Fulfill the conversion.
1
2 // Open Type1 font
3 string fontPath = Path.Combine(DataDir, "Courier.pfb");
4 FontDefinition fontDefinition = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fontPath)));
5 Font font = Font.Open(fontDefinition);
6
7 // Type1 output settings
8 string outPath = Path.Combine(OutputDir, "Type1ToTtf_out1.ttf");
9 FileStream outStream = File.Create(outPath);
10
11 // Convert type1 to ttf
12 font.SaveToFormat(outStream, FontSavingFormats.TTF);
Convert font formats from Type 1 to Woff
For this you will need to take the next steps:
- Open
Type1
font. - Add the output settings.
- Fulfill the conversion.
1
2 // Open Type1 font
3 byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "Courier.pfb"));
4 FontDefinition fontDefinition = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new ByteContentStreamSource(fontMemoryData)));
5 Font font = Font.Open(fontDefinition);
6
7 // Woff output settings
8 string outPath = Path.Combine(OutputDir, "Type1ToWoff_out3.ttf");
9 FileStream outStream = File.Create(outPath);
10
11 // Convert type1 to woff
12 font.SaveToFormat(outStream, FontSavingFormats.WOFF);
Convert Type 1 to WOFF2
Follow the written below algorithm to convert the fonts:
- Open
Type1
font. - Notify the next output settings.
- Fulfill the conversion.
1
2 // Open Type1 font
3 byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "Courier.pfb"));
4 FontDefinition fontDefinition = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new ByteContentStreamSource(fontMemoryData)));
5 Font font = Font.Open(fontDefinition);
6
7 // Woff2 output settings
8 string outPath = Path.Combine(OutputDir, "Type1ToWoff2_out4.ttf");
9 FileStream outStream = File.Create(outPath);
10
11 // Convert type1 to woff2
12 font.SaveToFormat(outStream, FontSavingFormats.WOFF2);
For getting more examples of using the solution go to the Aspose.Font.Examples.sln solution, in the net-examples of the Aspose.Font Documentation Github repository.
Aspose also offers you a free online Font Conversion application where you can try the existing functionality.