Well it turned out my font WAS broken BUT it wasn't my fault! :)
I found this post
https://stackoverflow.com/questions/25404145/register-font-is-corrupting-ttf-file
Maven apparently corrupts ttf files when copying them to the target
directory. So I had to add the following to my pom.xml and now it works!
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
On 1/12/21 8:20 PM, Tilman Hausherr wrote:
Hi,
Maybe your font is broken, maybe you have an outdated PDFBox version,
or you have resource filtering on. To check whether it's the later
one, try loading from a file.
Tilman
Am 13.01.2021 um 01:19 schrieb Ken Southerland:
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.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]