I'm trying to generate PDF document in Java using iText. link
But I also want to give users an opportunity to choose which font to use for the document. There are many fonts, installed in the system, I can list them using
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
but when I try to pass font names to BaseFont
constructor directly
BaseFont.createFont(s, BaseFont.IDENTITY_H, true);
I get an exception like
com.lowagie.text.DocumentException: Font 'Abyssinica SIL' with 'Identity-H' is not recognized.
Another option is to pass to the BaseFont
the path to the font file (either stored inside jar or somewhere on the system), but in the first case I have to deploy all the fonts with my application, and in the second case I have to think of a way of getting system font files locations. As far as I know, Java puts a layer of abstraction over fonts - public API doesn't know anything of paths, and usage of private API (something like FontManager) is discouraged.
Yet another option is to use constants, declared in BaseFont , but that gives only 4 fonts (Courier, Helvetica, Symbol and Times Roman).
Is there a way to use system fonts in PDFs, generated with iText without deploying them with application and using workarounds like FontManager?