Loading and Extracting Data | Java

The examples use 29645.cff. Adapt getDataDir() and the relative input path in the snippets to your font location.

Load CFF Font from Disc

Aspose.Font for Java API lets you open CFF Font files in your java applications. CFF font files stored on disc can be loaded by using the following steps.

1String fileName = Paths.get(getDataDir(), "..", "CFF", "29645.cff").normalize().toString();
2FontDefinition fd = new FontDefinition(FontType.CFF,
3        new FontFileDefinition("cff", new FileSystemStreamSource(fileName)));
4CffFont cffFont = (CffFont) Font.open(fd);

Load CFF Font from Byte Array

You can also load a CFF font from a byte array using ByteContentStreamSource. This example reads the file with Files.readAllBytes; handle or declare IOException in your application.

1byte[] fontMemoryData = Files.readAllBytes(
2        Paths.get(getDataDir(), "..", "CFF", "29645.cff").normalize());
3FontDefinition fd = new FontDefinition(FontType.CFF,
4        new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData)));
5CffFont cffFont = (CffFont) Font.open(fd);