Завантажити, витягти дані та зберегти з TTF | Java

Завантажте шрифт TrueType з диска

API Aspose.Font для Java дозволяє читати типи шрифтів TrueType із файлів, що зберігаються у вашому цифровому сховищі. Файли шрифтів TrueType, що зберігаються на диску, можна завантажити, виконавши такі дії.

1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
2String fileName = Utils.getDataDir() + "Montserrat-Regular.ttf"; //Font file name with full path
3
4      FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
5      TtfFont font = (TtfFont) Font.open(fd);        

Зберегти шрифт TTF

Після завантаження файлу TTF ви можете працювати з файлом шрифту, оновити деякі параметри та захотіти зберегти файл на диск. Aspose.Font для Java дозволяє зберегти файл TTF на диск за допомогою наступних кроків.

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
 2byte[] fontMemoryData = Utils.getInputFileBytes("Montserrat-Regular.ttf"); //Font file name with full path
 3
 4      FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new ByteContentStreamSource(fontMemoryData)));
 5      TtfFont font = (TtfFont) Font.open(fd);
 6      
 7      //Work with data from just loaded TtfFont object
 8
 9      //Save TtfFont to disk
10      //Output Font file name with full path
11      String outputFile = Utils.getDataDir() + "Montserrat-Regular_out.ttf";
12
13      font.save(outputFile);

Щоб дізнатися більше прикладів, перейдіть до рішення Aspose.Font.Examples.sln, у * net-examples* папки [Aspose.Font Documentation](https://github. com/aspose-font/Aspose.Font-Documentation) репозиторій Github.

Також перегляньте наші безкоштовні онлайн- Програми для обробки шрифтів, щоб дізнатися, як цю функцію можна реалізувати у веб-рішенні.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.