As far as I can tell, there is no direct way to determine if a font can be embedded. I did a quick search, and I donβt think itβs possible except using the catch catch method mentioned in Eric's comments.
// 1) have a list of all fonts ArrayList allAvailableFonts; // 2) second list of fonts that that can be embedded ArrayList embedableFonts; //Iterate through every available font in allAvailableFonts for( .... allAvailableFonts ..... ) { boolean isFontEmbeddable = true; try { // try to embed the font } catch( DocumentException de) { //this font cannot be embedded isEmbeddable = false; } if( isEmbeddable ) { // add to list of embeddable fonts embedableFonts.add ( font ); } }
Perhaps you may actually be doing hardcore and making your own calls on Windows Apis to get the same result, but I think it works too much for a simple task like this.
Some research has been done to find out how this exception is thrown by Java.
The code that throws the above exception can be found here. http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htm Line number 367 368
if (!justNames && embedded && os_2.fsType == 2) throw new DocumentException(fileName + style + " cannot be embedded due to licensing restrictions.");
The interesting part that should be noted is the condition os_2.fsType == 2
os_2 is an instance of WindowsMetrics , see line 174 here http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htm
Search WindowsMetrics on Google, and that was what I got.
This explains that the fsType parameter contains information about whether the font can be embedded. http://www.microsoft.com/typography/otspec/os2ver3.htm#fst
The explicit equivalent of WindowsMetrics used in itext http://www.docjar.org/docs/api/com/lowagie/text/pdf/TrueTypeFont.WindowsMetrics.html
source share