TFlexCelPdfExport Error trying to embed font 'Calibri' in the document

if i call PDF.Export(Filename) then on one of my Computers i get this error:

    Error trying to embed font 'Calibri' in the document.
Font licensing doesnt allow embedding.

I am using following code:

if ExelSave then
begin
  Xls.Save(dateiName);
  Pdf := TFlexCelPdfExport.Create(Xls, True);
  try
    pdf.FallbackFonts := 'Arial Unicode MS'; // did not help
    PDF.FontEmbed := FlexCel.Pdf.TFontEmbed.Embed; // did not help
    Pdf.PdfType := TPdfType.Standard;
    Var Dn:String;
    Dn:=dateiName.Replace('.xls', '.pdf');

    Pdf.export(Dn); //<<<< error on this Line

  finally
    Pdf.Free;
  end;
end;

I read the document "FlexCel PDF Exporting Guide" it say that i have to findout if the Font Calibri is installed.
Yes the font Calibri with 6 fontTypes are installed in Windows\Fonts.

Any ideas what i can do?

Hi,
It looks like you have a different version of calibri that doesn't allow embedding inside documents. I wonder if you go to \Windows\Font, double click in Calibri, then go to properties, is the font listed as "Editable"? This is how I see it here (and there are no problems embedding it)

In any case, this is a check FlexCel does to ensure you aren't embedding a font that you are not licensed to embed. If you know your version of Calibri is legally licensed to embed, you can ignore this message by useing TFlexCelPdfExport.UnlicensedFontAction Property | FlexCel Studio for VCL and FireMonkey documentation

like:
pdf.UnlicensedFontAction := TUnlicensedFontAction.Ignore;

You can also set up a "replacement font" that will be used for fonts whose license doesn't allow embedding them into other documents. But the strange thing in all of this is that calibri license, as far as I know, allows embedding. So I am interested to know if you have an special version of it.

This works.

My Font is Editable like you show it.
My Fileversion is 6.23

Can you email me the font to adrian@tmssoftware.com? I'd like to find out what is wrong with it, as it shows as "Editable". Calibri is just the font used in 99% of documents and we never seen it flagged as not embeddable. So I'd like to investigate it a little more, maybe there is some bug in our code to detect the licensing requirements.

This is the Font i am using.

defektCalibri.zip (3.7 MB)

Thanks for the files. It is weird, I can't see the error here, and I can't understand how it can happen given that the font has a "editable" attribute in its licensing (as it should be for calibri). I've re-reviewed the code, but it looks correct (and it is working correctly in this machine). I am a little out of ideas, but I'll try to think about it a little more.

I am experiencing this same issue with FlexCel generating PDF from an Excel template. It began early March and is occurring even with installed versions of the program that I have on my computer. However the program installed on another computer is able to generate a PDF from Excel template with Calibri font.

I did install FlexiPDF and then Adobe Acrobat 2020 the week before noticing the issue. Also believe there was a Office 365 update. Not sure if any of that is connected, but maybe there is something common that might be cause.

Can you search for calibri*.ttf in your hard disk, and check the properties of all the files to see if they have "editable" permissions?

If possible, I'd also like if you can create a new Console Application, and paste the code below, then run the app and tell me the results:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  FlexCel.VCLSupport,
  _PdfTrueType.TPdfTrueType,
  _PdfTrueType.TFontDataReader,
  _PdfTrueType.TChunkByteArray,
  _UIClasses.TUIFont,
  _PdfFontFactory.PdfFontFactory,
  _UIClasses.TUIFontStyle,
  _PdfConsts.TPdfFontFolderNotFoundAction;

procedure DumpFont(const Name: string; const fs: TUIFontStyleSet);
var
  pdf: TPdfTrueType;
  FontData: TChunkByteArray;
begin
  FontData := PdfFontFactory.GetFontData(TUIFont.CreateNew(Name, 12, fs), 'c:\windows\fonts', TPdfFontFolderNotFoundAction.DefaultBehavior);
  pdf := TPdfTrueType.Create(TFontDataReader.Create(FontData), 'test', true);
  WriteLn('Name: ', pdf.PostcriptName);
  WriteLn('EmbedForbidden: ', pdf.EmbedForbidden);

  WriteLn;

end;

begin
  DumpFont('Calibri', []);
  DumpFont('Calibri', [TUIFontStyle.fsBold]);
  DumpFont('Calibri', [TUIFontStyle.fsItalic]);
  DumpFont('Calibri', [TUIFontStyle.fsBold, TUIFontStyle.fsItalic]);

  DumpFont('Calibri Light', []);
  DumpFont('Calibri Light', [TUIFontStyle.fsBold]);
  DumpFont('Calibri Light', [TUIFontStyle.fsItalic]);
  DumpFont('Calibri Light', [TUIFontStyle.fsBold, TUIFontStyle.fsItalic]);
  readln;
end.

I edited the code in my previous post to try all font variations, in case the problem is not with calibri, but with a variant.

The output shows EmbedForbidden: TRUE for all Calibri variants. I reran with Arial and all were marked false. Both font properties show Font embeddability as Editable

I have been able in Excel to use Save to PDF to generate a PDF of the template that is being used when the error occurs.

I really can't figure out what is going on. Even when we have 2 customers now with the problem, this is not a common thing. In fact I could only find another email in all our email history about a similar issue, and the email was from Kipper Gerald, the same customer that created this issue here. We have tens of thousands of registered users and if this was something common, I would expect to have heard more about it.

But yes, you are having an issue, and somehow we aren't reading the fonts right (or not the right fonts). Excel can embed them but that doesn't mean much, since latest Excels tend to come with their own fonts and don't use those in c:\Windows\Fonts. But the part I can't understand at all is that if I use the fonts you are having issues here, I don't see any message.

So ok, let's try a new test. This code will create some .font files for all the font files it is reading, please zip them and send them. Also let me know which FontFlags you get.

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  FlexCel.VCLSupport,
  _PdfTrueType.TPdfTrueType,
  _PdfTrueType.TFontDataReader,
  _PdfTrueType.TChunkByteArray,
  _UIClasses.TUIFont,
  _PdfFontFactory.PdfFontFactory,
  _UIClasses.TUIFontStyle,
  Classes,
  _PdfConsts.TPdfFontFolderNotFoundAction;

procedure DumpFont(const Name: string; const fs: TUIFontStyleSet);
var
  pdf: TPdfTrueType;
  FontData: TChunkByteArray;
begin
  FontData := PdfFontFactory.GetFontData(TUIFont.CreateNew(Name, 12, fs), 'c:\windows\Fonts', TPdfFontFolderNotFoundAction.DefaultBehavior);
  pdf := TPdfTrueType.Create(TFontDataReader.Create(FontData), 'test', true);

  var FontBytes := TFileStream.Create('..\..\' + pdf.PostcriptName + IntToStr(byte(fs)) + '.font', fmCreate);
  try
  FontData.WriteTo(FontBytes, 0, FontData.Length);
  finally
    FontBytes.Free;
  end;

  WriteLn('Name: ', pdf.PostcriptName);
  WriteLn('EmbedForbidden: ', pdf.EmbedForbidden);
  WriteLn('FontFlags: ', pdf.FontFlags);

  WriteLn;

end;

begin
  DumpFont('Calibri', []);
  DumpFont('Calibri', [TUIFontStyle.fsBold]);
  DumpFont('Calibri', [TUIFontStyle.fsItalic]);
  DumpFont('Calibri', [TUIFontStyle.fsBold, TUIFontStyle.fsItalic]);

  DumpFont('Calibri Light', []);
  DumpFont('Calibri Light', [TUIFontStyle.fsBold]);
  DumpFont('Calibri Light', [TUIFontStyle.fsItalic]);
  DumpFont('Calibri Light', [TUIFontStyle.fsBold, TUIFontStyle.fsItalic]);
  readln;
end.

Got the following output
Name: Calibri
EmbedForbidden: TRUE
FontFlags: 32

Name: Calibri-Bold
EmbedForbidden: TRUE
FontFlags: 262176

Name: Calibri-Italic
EmbedForbidden: TRUE
FontFlags: 96

Name: Calibri-BoldItalic
EmbedForbidden: TRUE
FontFlags: 262240

Name: Calibri-Light
EmbedForbidden: TRUE
FontFlags: 32

Name: Calibri-Light
EmbedForbidden: TRUE
FontFlags: 32

Name: Calibri-LightItalic
EmbedForbidden: TRUE
FontFlags: 96

Name: Calibri-LightItalic
EmbedForbidden: TRUE
FontFlags: 96

Projects.zip (3.4 MB)

Reran with Arial and it had FontFlags:32 but EmbedForbidden: FALSE

I don't understand what you are trying to say.
Can you please use understandable sentences.

Hi,
This is still strange. It looks like the code reading the fonts is fine, since the fonts you sent in Project.zip are "Restricted" (you can see if be renaming them from .font to .ttf and opening the properties):

Now the question is where are those fonts "restricted" coming from, since for both of you, the fonts in the c:\Windows\fonts are editable.

I'll try creating an app to try to figure out where those fonts are coming from, I'll post it here later

I don't understand what you are trying to say.
Can you please use understandable sentences.

I am just trying to find out why you are getting "restricted" fonts instead of the normal fonts. Sorry if it isn't clear, but please let me know which is what wasn't understandable and I'll try to rewrite it

That is the Text i can not understand, what you want to say to me.

This is the Excel File i use.
Maybe you can see anything in there
VorlageRechnung.xls (40 KB)

Hi,
Maybe you are getting confused because we are 3 people in this discussion, you, myself and another customer who has the same problem (Szuminsky Neil).

I asked to any of you to run some code I posted, and he run it, with Calibri and Arial, and posted the results.

Maybe if you are reading the posts from the email it is more complex to follow, but in the thread: TFlexCelPdfExport Error trying to embed font 'Calibri' in the document - #17 by Kipper_Gerald
it should be simple to see what are my posts and what are the answers from you or from Neil.

By the way, I think I know what is happening, I am creating a new app so any of you can run it, and we can confirm it. If it is what I think, it isn't related to the xls file you are converting, but to the fonts you have in the Fonts folder.

Thanks Adrian
if you have a link to a font that is working, i will install this and try if it work.