IText:正在注册字体:找不到文件或资源 [英] IText: registering font: not found as file or resource
本文介绍了IText:正在注册字体:找不到文件或资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Windows平台上进行开发.我的maven项目具有以下字体资源结构:
I am developing on windows plattform. My maven project has the following structure for font resources:
src/main/resources/package/name/fonts
我尝试按以下方式注册字体:
I try to register a font as following:
FontFactory.register("package/name/fonts/fontname.otf");
但是我得到了错误:
package/name/fonts/fontname.otf not found as file or resource
我的失败是什么?
谢谢
推荐答案
首先,我使用getResource()获得正确的路径:
First I get the correct path with getResource():
String pathtofont = "/package/name/fonts/fontname.otf";
String fontname = myworkingclass.class.getResource(pathtofont).toString();
然后我将其注册:
FontFactory.register(fontname);
重要的是字体的路径以/开头.
Important is that the path to font starts with a /.
这篇关于IText:正在注册字体:找不到文件或资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文