vandeseer / easytable

Small table drawing library built upon Apache PDFBox
MIT License
246 stars 94 forks source link

How to use a font which is not default in PDFBOX #75

Closed Daya2006 closed 4 years ago

Daya2006 commented 4 years ago

is there a way i can use a ttf file for a font to use a font other than the default ones? need to use proxima nova

vandeseer commented 4 years ago

Yep, see here for instance:

https://github.com/vandeseer/easytable/blob/master/src/test/java/org/vandeseer/integrationtest/VerticalTextCellTest.java

Daya2006 commented 4 years ago

Gettin null pointer exception:

final InputStream resourceAsStream = this.getClass() .getClassLoader() .getResourceAsStream("proxima_nova_reg-webfont.ttf");

    ownFont = PDType0Font.load(doc, resourceAsStream); 

in the above(ownFont = PDType0Font.load(doc, resourceAsStream); ) , the file is present in the location.

java.lang.NullPointerException at org.apache.fontbox.ttf.MemoryTTFDataStream.(MemoryTTFDataStream.java:45) at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106) at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:78)

Daya2006 commented 4 years ago

worked fine after i did ownFont = PDType0Font.load(doc, new File("proxima_nova_reg-webfont.ttf"));