The embedded font 'Arial Unicode MS Bold' is not found

Aspose.Pdf .NET 10.5.1.0

We're seeing this error when saving a new (created with Pdf.Generator) PDF document on one server/environment, while all other servers/environments running the same code work fine:
The embedded font 'Arial Unicode MS Bold' is not found. Make sure that you set correct path to the font file.

We don't use/embed or call for "Arial Unicode MS Bold" in our code, and we don't have that font installed on any of our servers.

Because our issue seems to be environment related, and because there was a recent issue similar to this,
My question to you is:
What are all of the possible scenarios in your code that can throw this exception?

Here is the full exception with the obfuscated stacktrace:

System.ApplicationException

Source: Aspose.Pdf

Message: The embedded font 'Arial Unicode MS Bold' is not found. Make sure that you set correct path to the font file.

Stack Trace:
at .?.??(String , Boolean , String , Exception )
at .?.FindFont(? , String , String , Boolean , Boolean , Boolean , String , Boolean )
at .?.?(String , String , Boolean , Boolean , Boolean , String , Boolean )
at .?.??(TextInfo )
at ?..??(Text , Pdf )
at ?..??(Pdf , Section , Table , Row , Cell , Text , e ,  , Boolean )
at ?..?(Pdf , Section , HeaderFooter , Table , Row , Cell , Text , e ,  , Boolean )
at ?..??(Pdf , Section , Table , Row , Cell , e ,  )
at ?..?(Pdf , Section , Table , Row , e ,  )
at ?..??(Pdf doc, Section currentPart, HeaderFooter hf, Table table, e assignInfo,  useType, Boolean isFirst, & breakTableNextPart)
at ?..??(Pdf , Section , e )
at ?.?.?(Pdf )
at ?.?.??( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)

Thank you,
Joey Latino

Can I get any help with this?

Is there any more information I can provide to help with the answer?

I’m looking for the scenarios in the Aspose.Pdf.Generator.Pdf.Save(Stream) stack that might throw an exception for missing fonts, especially fonts that we don’t use.
For example, why is “FindFont” looking specifically for “Arial Unicode MS Bold”?

Again, this works on all environments except one, so we’re trying to track down what the code is looking for so we can determine the difference in this one environment and resolve it.

Thanks,
Joey

Hi Joey,


Thanks for using our API’s and sorry for the delayed response.

Can you please share the code snippet you are using to generate the PDF document and also please share some details regarding your working environment i.e. Environment over which the code works and the environment on which code fails, so that we can try replicating the issue in our environment.

Unless we are able to replicate the issue in our environment, we might not be able to share the possible reasons behind this issue. We are really sorry for this inconvenience.

Hi Nayyer,


The bulk of the code we’re using to generate the Document is rather large and proprietary, so I cannot share that code, unfortunately.
But here’s the final snippet when we save the Document to the stream:
// Save to stream
var fileStream = new MemoryStream();
Document.Save(fileStream);
return fileStream;

We’ve been using this same code for a couple of years now under version 7.9 with very few changes, and a few months ago, updated to version 10.5.
Again, all other 4 server environments plus several local dev machines work fine with the current code. We only have an issue with one specific server environment (the newest one). All server environments are running the same OS (Win 2008 R2), and are intended to be set up identically.
However, it is possible that there is some configuration that may be different on this server that we are not aware of. That why I’m trying to get more information about the scenarios in which the FindFont method in your code is throwing exceptions, or why it is even calling FindFont to begin with.
I’d like to point out again, that there was a recent issue (linked above) in which this type of exception was thrown because your code was unexpectedly reading a value in the Config file.
I’m looking for scenarios such as that.
Is there still code looking in the config files? Is the code assuming things about the environment? Is there “test” code unintentionally being executed because of some logic is unexpectedly resolving to “true” based on environmental factors?
Any of this type of information may be helpful.

Thanks!
Joey

Hi Joey,


Thanks for sharing the details.

As a normal rule or practice, we request our customers to share the code snippet so that we can test it and figure out the reasons behind any particular problem. However as per your reply, you might not be able to share the code snippet, so I am in coordination with product team to figure out some clue which may help us in identifying the reason behind this problem and as soon as we have some further updates, we will let you know.

Hi Joey,


Thanks for your patience.

We have further investigated the issue reported earlier and also have investigated code related to old generator’s obfuscated stacktrace. As per our understanding, font encoding seems to be the reason of exception.

It can be concluded from code that an exception which is shown on stacktrace is not the real exception and it’s only an exception thrown from catch block to indicate a problem and this exception can be thrown only when special Boolean flag is set - IsFontNotFoundExceptionThrown and this flag in generator code can only set in 1 place - method FontResource.FindResource().

Please note that the exception is thrown from method FontResource.FindResource() and this method throws exception when it tries to load configuration XML file and the desired resource file is not found. The flag passed in this method, which tries to load config xml, is set to search for some resource i.e. Encoding, FontAFM, FontPFM, FontOutline. So any of these resource categories was not found and caused the exception.

As per my understanding, the most probable resource category here is encoding because block for another categories marked with comment “Multiple Master fonts” but the problem font “'Arial Unicode MS Bold” is not the font from multiple master fonts category.

However to have more precise conclusions, its necessary to have your code snippet and the possibility to debug it without these 2 things can be incorrect.

Thank you Nayyer,


This helps focus our efforts.
I’m working on creating some sample code to be able to reproduce the issue.
Again, the trouble is that this issue only happens on one out of several servers running the same code.
You mentioned the “old generator”. While we’re using version 10.5 of the library, it’s true that we’re using code that was written (about 5?) years ago, so it very well could be outdated.
While I’m working on providing some sample code to you, can you provide any more information about why the flag to load the config xml file was set to true in FindResource(), or which config xml it may be looking for?
Does it look for the host application’s config file (web.config / app.config)?
If we can get past the issue for now by adding a key in our config, that’s fine for us until we get a chance to update our code to use the newer API.

Thank you,
Joey
jmlati:
This helps focus our efforts.
I'm working on creating some sample code to be able to reproduce the issue.
Hi Joey,

The code snippet will surely help us in replicating the issue in our environment and obviously it can lead us towards figuring out the actual reasons behind this problem.
jmlati:
Again, the trouble is that this issue only happens on one out of several servers running the same code.
You mentioned the "old generator". While we're using version 10.5 of the library, it's true that we're using code that was written (about 5?) years ago, so it very well could be outdated.
While I'm working on providing some sample code to you, can you provide any more information about why the flag to load the config xml file was set to true in FindResource(), or which config xml it may be looking for?
Does it look for the host application's config file (web.config / app.config)?
If we can get past the issue for now by adding a key in our config, that's fine for us until we get a chance to update our code to use the newer API.
I am in coordination with product team to gather further information based on above feedback and will get back to you soon.

Hi Joey,


Thanks for your patience.

Following are our observations against your last queries.

why the flag to load the config xml file was set to true in FindResource()” ?

It appears that flag to load xml file was set to true to enforce loading of font resources if they are was not loaded to moment when FindResource() is called.

which config xml it may be looking for” ?

It’s difficult to answer this question without debugging. Direct code of method, as FindResource do not work with any xml document at all and all of the methods linked with FindResource also do not work with xml files. Only one possible thing which could be concluded from code is the xml file passed to public method Aspose.Pdf.Generator.Pdf.BindXML(XmlDocument xmlDoc, string xslFile). The font parameters like FontName, IsCoreFontUsed, FontAfmFile, FontPfmFile, FontOutlineFile are accessed from xmlDoc file. Information about these parameters is refreshed for case when FindResource() method is being called and internal TextWriter object has no resources and also flag loadxml is set to True.

Thank you very much for your replies Nayyer.

We’re still looking into this, but the priorities shifted for a while.
I imagine that I’ll be able to work on some sample code for you soon.
In the meantime, I will try to use your responses regarding the FindResource method to debug our code and failing environment further.

Joey

Thank you Nayyer, I was able to figure this out.

Your clues about the XML helped narrow down where to look.

The problem was that the font map was being cached:
Document = new Pdf
{
DefaultFontName = DefaultFont,
IsCoreFontUsed = false,
IsTruetypeFontMapCached = true,
TruetypeFontMapPath = TempFolder,
};
When the application was first executed several months ago, we received the error about the missing font, but we didn’t realize that an XML file “Aspose.Pdf.TruetypeFontMap.xml” was generated that contained the available fonts in the system.
The missing font was subsequently installed, but the cache was never refreshed/recreated.
Just now, I found and deleted the cache file, and re-ran the app. A new cache file was created including the required font, and all is now working fine.

Thank you for your help and diligence in this matter.

Joey


Hi Joey,


Thanks for sharing the details.

Yes you are correct. Once the TrueTypeFontMap.xml is created, if any new font is installed on system, the file is not updated automatically and you need to delete existing XML file and then re-run the code which automatically adds newly installed fonts information in newly created XML file. Please continue using our API’s and in the event of any further query, please feel free to contact.