Why do I get a message saying 1.not.found.as.a.resource?

无人久伴 提交于 2019-12-08 09:23:31

问题


What might cause

new Font(Font.HELVETICA, 11f, Font.BOLD)

or

BaseFont.createFont(BaseFont.HELVETICA, 'Cp1252', BaseFont.NOT_EMBEDDED)

to start returning the following??

com.itextpdf.text.DocumentException: No message found for 1.not.found.as.resource

itext 5.5.6 jar on Max OSX 10.10


回答1:


It seems that you are not using the "pre-canned" jar, but that you have created your own jar. That self-made jar only contains the Java class files. It misses resources such as the language (.lng) and the Adobe Font Metrics (.afm) files.

If the above assumption is wrong, then at least this is right:

  • Instead of the actual error message, you get the key to an error message that is stored in a .lng file: 1.not.found.as.resource. This key is used to find the actual error message in the language of your OS (English, Dutch and Portuguese are supported; the default is English).
  • The actual error message (should en.lng be found) would have been: "Helvetica not found as a resource" (the 1 in 1.not.found.as.resource is a placeholder). This message tells you that the file Helvetica.afm can't be found. This file contains the metrics of every glyph in the font Helvetica (regular). Without those metrics, you can't create a proper PDF.

This explains what happens. Your question doesn't contain sufficient information to explain why it happens. All of this shouldn't be a problem when using the correct jar with a JDK that knows how to read resources from a jar. The fact that you write "What might cause ... to start returning the following" indicates that it has worked for you before. Think of what you have changed between the last time it worked and the first time it stopped working (e.g. changing the OS, changing the JVM,...). That will probably be the culprit.



来源:https://stackoverflow.com/questions/31357638/why-do-i-get-a-message-saying-1-not-found-as-a-resource

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