Good day, dear colleagues.
Could you please help me to understand why is this error appears when the spring boot app is packed into the jar and no cause when app is being debugged from IDE?
var is = getClass().getResourceAsStream("/fonts/2211.ttf");
byte[] b = new byte[is.available()];
is.read(b);
var fontProgram = FontProgramFactory.createFont(b); // <-- com.itextpdf.io.IOException: Type of font is not recognized.
My thought was that maybe *.ttf got corrupted being packed into jar, so I tried to get is as a byte array from resources, and further comparison says they are identical with the original *.ttf file outside of jar.
Any ideas?
Don't use is.available()
to determine the length of the resource because in general that's not what this method returns (see many other questions, e.g.
this one).
Instead copy the whole stream via a buffer or use a utility method.
As you use iText 7, you can use its com.itextpdf.io.util.StreamUtil
utility
byte[] b = StreamUtil.inputStreamToArray(is);