I am trying to display write some text which may be in a foreign
alphabet e.g. Cyrillic. The default fonts in pdfbox do not handle these.
So I'm attempting to load a TrueType font that will handle it but I get
the following error when I do so ...
java.io.IOException: Illegal seek position: 3216895935
at
org.apache.fontbox.ttf.MemoryTTFDataStream.seek(MemoryTTFDataStream.java:164)
at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:360)
at org.apache.fontbox.ttf.TTFParser.parseTables(TTFParser.java:173)
at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:150)
at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106)
at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:97)
at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:81)
I am trying fonts that came installed with Ubuntu, e.g.
/usr/share/fonts/truetype/freefont/FreeSerif.ttf
.
I have also tried FreeSerifBold.ttf and DejaVuSansCondensed.ttf with the
same result (only difference being the position number that it finds
illegal). My code to load the font is ...
try {
font = PDType0Font.load(document,
this.getClass().getResourceAsStream("/FreeSans.ttf"));
} catch (Throwable ex) {
logger.error("Can't import font into pdf document.", ex);
//
// These fonts don't have any special characters (e.g.
Cyrillic) and thus we try to import
// a font that does have this instead. But if that fails
then we at least fallback on these.
//
font = PDType1Font.HELVETICA;
}
... and FreeSans.ttf is in the root of my resources path (i.e.
resources/main/FreeSans.tif).
Thanks for any help on this issue. Cheers.