1

How can i import a new font to POI API with extensions ttf & otf , without install these fonts into the environment ?

Is there a jar that i should update it with the path of the new font ?

User
  • 573
  • 3
  • 15
  • 28
  • I have updated my answer. Please take a look: maybe you can use embedded object. – rdllopes Mar 17 '14 at 12:27
  • Do you mean you want to embed a font into an existing file, so it's somehow available when someone loads the file on a machine without the font, or do you mean to make the font available to Java so POI can correctly calculate font sizes? – Gagravarr Mar 17 '14 at 15:15
  • Yess, I want the put the file somewhere that make once the jar of the project installed in any environment no need to install the font first – User Mar 17 '14 at 15:24

2 Answers2

2

Normally

You cannot add fonts... You can think your (office) files just like HTML. Font lives outside the document. You just set the font name, family, etc.

Update:

However, someone has already tried to do that. Using embedded files, you could add font files.

Link:

http://apache-poi.1045710.n5.nabble.com/Font-embedding-into-XSLF-td5713937.html

It is far from easy. There's no easy way to insert embedded files.

Community
  • 1
  • 1
rdllopes
  • 4,897
  • 4
  • 19
  • 36
0

In the meantime I've implemented an API to embed the fonts easily. This version goes live with POI 4.1.0.

POI can't consume .ttf/.otf directly, but needs some help from googles sfntly. My demo project can be found under github/poi-font-mbender.

I won't provide a copy & paste of the sample class as you also need the rest of the sfntly library, which is not available as maven artifact.

kiwiwings
  • 3,386
  • 1
  • 21
  • 57