IText: registering font: not found as file or resource

拥有回忆 提交于 2019-12-24 19:38:49

问题


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");

But I get the error:

package/name/fonts/fontname.otf not found as file or resource

What is my failure?

Thank you


回答1:


First I get the correct path with getResource():

String pathtofont = "/package/name/fonts/fontname.otf";
String fontname = myworkingclass.class.getResource(pathtofont).toString();

then I get it registerd:

FontFactory.register(fontname);

Important is that the path to font starts with a /.



来源:https://stackoverflow.com/questions/44926209/itext-registering-font-not-found-as-file-or-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!