Get font file as a File object or get its path
file, fonts, java, path
Solution
Ok ... This will return the font file path :
String fontFilePath = FontManager.getFontPath( true ) + "/" + FontManager.getFileNameForFontName( fontName );
I have tried this in Windows and Linux and in both it worked fine.
Problem
I have a Font object in Java for a font file. I need to convert that object to a File object or get the font file path. Is there a way to do this? What I'm doing here is calling a method from an external library that loads a font file to use it in writing: ``` loadTTF(PDDocument pdfFile, File fontfile); ``` So I wanted to let the user choose a font from the ones defined in his operating system using : ``` GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = e.getAllFonts(); ``` Then when the user chooses a font, I pass it to the `loadTTF(...)` method to load it. Is there a bad practice here?