PDF Export Unicode Font Issue -- GDI+ Error 14

When calling TFlexCelPdfExport.ExportAllViisbleSheets(), I am sometimes receiving an exception with the message "Error in GDI+: 14 (FontFamily Not Found)."

I am creating some Excel cells that sometimes contain international characters. I have specified the font for these cells to be Courier New, because I need a monospace font in these cells.

The Excel creation always goes fine, but the PDF creation fails with the GDI+ 14 error when 
  1. International characters are used, AND
  2. The application is running on a PC that does not contain the font Arial Unicode MS
If I run the application on a PC that does have the Arial Unicode MS font (which is installed by MS Office), the PDF creation works. When I inspect the fonts used by the PDF, I see that Arial Unicode MS has been used in the PDF document.

I have tried setting TFlexCelPdfExport.FontMapping to all the available options, but that doesn't make a difference.

Do you have any ideas about what I can do to avoid this exception?

Thanks.

Hi,

Are you getting this exception when running outside delphi, or when debugging? If it is when debugging, then just press "continue" and the application should continue. The exception should be handled by FlexCel, but sadly if you are inside delphi, the debugger will break anyway. You might choose to ignore that exception type in the debugger if you prefer. But it shouldn't matter when running outside the debugger.

About fontmapping (and font embed), if your text contains unicode characters outside the ascii range, those settings will be ignored and the font will always be embedded. This is because the built in pdf fonts don't have those characters.

About why you are not seeing this if Arial Unicode is installed, it might be because Courier new doesn't have those characters, and the font is falling back to Arial unicode. (you can set the fonts to fall back when a character doesn't exists in a font by setting it like:
Note that Excel automatically falls back if the character doesn't exists, so you might think it is using courier new, but it might be using arial unicode to actually display the character.

For example, here is a cell in Excel using courier new and with a chinese character:



As you can see, the chinese character isn't really Courier new, or the first line with 3 characters would be the same width as the second. If you look further you'll see it is using Arial Unicode to do the substitution. So don't trust what Excel shows.

Finally, FlexCel has a way to track what it is really doing, by using FlexCelTrace. Look at Demo\Delphi\Modules\10.API\X0.Handling Errors to see how to use it, and try to make a run and log all errors reported by FlexCel trace. It should bring some light on what is actually happening under the hood.

Adrian, thank you so much for your quick and helpful response. The pointer to pdf.FallbackFonts seems to have solved my problem. I will also keep FlexCelTrace in mind and give it a try soon.



By the way, FlexCel has given us some great results and helped us create an impressive feature for our product.

Just a note: If you remove the fallback font, then you might be getting an empty square character: â˜ in those characters that don't exist in the original font (in this case courier new). When you get time, give FlexCelTrace a try, as it will tell you what characters are being lost.


I think the best solution might be to either find a font that you know is in every machine this app will run and has those characters, or to redistribute some font that has those characters with your app, installing it as Excel does, and then using that font as fallback. But if depends if you are losing some information by the characters being replaced by squares.

That's great! Thanks for letting me know :)