1

I'm trying to export a Draw2D Figure to a PDF file, using PDFBox.

The software will be used on both Windows and Mac OS X.

From the Figure I can get SWT font objects (org.eclipse.swt.graphics.Font). Available fonts are obtained from the JFace FontRegistry.

To embed a font in the PDF, I can embed a TrueType font with PDTrueTypeFont.loadTTF( PDDocument doc, File file ) or variants.

Given an SWT font object or a font name, how can I get the file path to the font file?

EDIT:

There's a similar question here: Get font file as a File object or get its path. However, the accepted answer is fragile and platform-specific. It relied on an internal API that changed between Java 6 and Java 7. This question seeks a solution that is cross-platform and does not couple to internal implementation details.

Community
  • 1
  • 1
Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
  • I've been wrestling with the same kind of problem--my hack around it was to index the names, paths, and some other attributes of TTF files in common directories. I used [sfntly](http://code.google.com/p/sfntly/) to do that. It's very very very very hackish but it worked for what I needed. – jgriego Nov 19 '13 at 20:16
  • Thanks for the sharing the idea. I had thought of doing something similar, but was concerned that any set of well-known common font directories that I specify might be incomplete, and about whether there would be a startup lag that increased with the number of fonts on the user's system. – Andy Thomas Nov 19 '13 at 20:38

0 Answers0