Free Support Forum - aspose.com

Including a Font Directory with CellsHelper- doesn't seem to work

Hello,

I’m using Cells 8.4.1.0 and including a Font Directory for inclusion when converting to PDF. The problem is that the output PDF isn’t including the TTF font.

Here’s my code:

string fontDir = GetFontDirectory(); // D:\MyFonts
if (fontDir != null)
{
if (!CellsHelper.FontDirs.Contains(fontDir))
CellsHelper.FontDirs.Add(fontDir);
}

workbook.Save(ms, Aspose.Cells.SaveFormat.Pdf);

Am I missing something?

Thanks,

Michael

Hi,

Thanks for your posting and using Aspose.Cells.

Please download and use the latest version: Aspose.Cells for .NET 8.5.1 it works fine.

I have tested this issue with the following sample code and the attached source excel file. The source excel file has a value Test in cell A1 which is only visible when the custom font named CatsAlphabet is installed. It’s font size is 72.

I have also attached the custom font i.e CatsAlphabet and output PDF generated by the following code for your reference. As you can see in the output PDF that Test is rendered fine in CatsAlphabet. Please check the screenshot attached showing the output PDF.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


string fontDir = @“F:\Shak-Data-RW\Downloads”;

if (fontDir != null)

{

if (!CellsHelper.FontDirs.Contains(fontDir))

CellsHelper.FontDirs.Add(fontDir);

}


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.pdf”);

In the test code, I can get it to work fine, but in my “real” project, it doesn’t work. Hmmm, I’m stumped.

Hi Michael,


We will need more details of your environment as well as the real project. However, please first give a try to the latest version of Aspose.Cells for Java 8.5.1.2 on your side to see the results. In case the problem persists, please provide us the following information/artifacts.

  • Operating system version
  • Operating system architecture
  • JDK vendor
  • JDK version
  • List of JVM arguments being passed to the process/program (if any)
  • Sample spreadsheet
  • PDF converted with latest version
  • Fonts used in the spreadsheet acquired from the environment where your real project is running
  • Demo application replicating the issue

Please note, you can enable the font substitution warnings to know what font has been replaced. Moreover, I would also suggest you to double check the font location before setting it to the CellsHelper.setFontDir(s) method. Here is a useful article describing how Aspose.Cells for Java uses the fonts for rendering.

Hi Babar,

My issue is on the .NET version. I’ll continue to try some things here and update the case with my findings.

Michael

Using your suggestions, I implemented the WarningCallback.

In my test project (where embedding the font works), naturally, nothing is captured in the WarningCallback.

However, in my “real” project, the WarningCallback captures the following:
WARNING INFO: Font substitution: Font [ Annabel Script; Regular ] has been substituted in Cell [ A2 ] in Sheet [ Basic ].

At least I can see now that font substitution is definitely occurring. Now the question is "why?"

I’ve looked to ensure the application (AppPool) has access to the directory, and it appears to. If you have any other thoughts, that would be appreciated.

Hi,

Thanks for you posting and using Aspose.Cells.

It means Aspose.Cells is unable to find Annabel Script font. Please install it in your Windows fonts. If it is already installed, then uninstall it and re-install.

Please also provide us your sample excel file, actual output excel file and the expected output excel file as well as the Annabel Script font so that we investigate this issue at our end.

Please also give a try to latest version: Aspose.Cells
for .NET v8.5.1.2
and see if it makes any difference and let us know your feedback.

I still haven’t solved it. I tried 8.5.1.2, but no difference.

I have found that web apps running from within visual studio work, but those published to IIS don’t work.

Tomrorow I’ll try more with I directory security to see if the App Pool simply can’t see the directory.

Hi,

Thanks for your posting and using Aspose.Cells.

Probably, you are right. Aspose.Cells is unable to access your font. Could you please try the custom font given by me in above post both in your console application and in your web application after deployment and see if the string “Test” is rendered fine in CatsAlphabet font or not.

It will help you diagnose this issue at your end and you will be able to fix it.

Also, Aspose.Cells is able to work with TTF and TTC fonts and it does not work with other types of fonts like OTF. So check the type of your font and if it is in some other type then convert it into TTF or TTC font to fix this issue.

Hi Shakeel,

Using my test web app, both your font and my font work fine:
http://screencast.com/t/89ZXihHS

However, from my big web app, Cells still can’t find the font:
http://screencast.com/t/jZSur4Yalw

My font is a TTF, just like yours, obviously.

Strangely enough, from my big web application, it’s still not working (and I’m continuing to get a font substitution). I’ve confirmed that the App Pool account has access to the directory (and can write and read a text file in the same directory), so it doesn’t seem like directory permissions.

The code in my test application is copied directly over from the big application, so I don’t really see any alternatives there.

I also published my test app to IIS, to see if that made a difference. It worked just fine there, so I don’t see that it’s something about IIS.

If you have any further ideas, I’d be grateful to hear!

Take care,

Michael

Hi Michael,

Thanks for your feedback and using Aspose.Cells.

From your screenshot, it seems you have successfully experimented and observed the working of CellsHelper.FontDirs in your test machines.

Now the problem is specific to your production machine. Suppose you have fonts in C:\Windows\Fonts directory and there are several fonts like Arial, Times, Arial, Verdana, Annabel and CatsAlphabet etc.

And you have an excel file which uses these fonts. Now if C:\Windows\Fonts is accessible, then all of these fonts should be rendered fine and if it is not accessible by Aspose.Cells, then none of should be rendered.

It cannot happen that Arial, Times, Verdana and CatsAlphabet are found and rendered fine but Annable is not found. Since all of them are in same directory, so all of them should render fine.

Please experiment this scenario, do you see such a problem that other fonts are found from the directory but only Annabel is not found.

Please also provide us your Annabel font so that we could also experiment this issue at our end.

Thanks for your cooperation.

Here’s that Annabel Script font for you to check out.

What’s interesting is that even if the font is installed on the machine (and located in \Windows\Fonts), my production application doesn’t “find” the fonts and substitution occurs. It seems like the font substitutions aren’t working regardless of the location of the TTF files.
http://screencast.com/t/mWNBIh0MPg


Here’s my test template, too, just for reference.

Correction – after restarting IIS, the fonts from \Windows\Fonts do embed correctly.

It’s only the ones in the separate directory that continue to give me trouble.

Hi Michael,


Thank you for keeping us updated. On our side, we have also performed a few test while using the latest version of Aspose.Cells for .NET 8.5.1.2 and by deploying the simple sample application on the IIS. Unfortunately, we are not able to replicate the said problem as we are seeing that the font is picked up and embedded in the resultant PDF fine. We are wondering if your test application (that works fine) is hosted on the same machine as of your original application (that does not work correctly). If both applications are hosting on same machine then you should compare the two applications for IIS & web settings. Moreover, please execute the the following simple lines of code in your main application just to be sure that the font file is accessible through IIS.

C#

Stream stream = System.IO.File.OpenRead(the ttf file in separate dir);
stream.Close();

I added the File.OpenRead() call, and it successfully reads the file, even in the production version. So we’re certain now that the directory is accessible and the file readable.


Hi again,


Thank you for testing out the scenario. It is very strange that Aspose.Cells for .NET API is not able to read the font file even though the file is accessible through IIS. Also we are not able to see the similar behavior on our side. What about comparing the two applications for web settings? Are you able to find any differences?

As per your previous comments, I believe you are able to workaround this situation by placing the custom font in the Windows/Fonts folder however, the same font in other directory cannot be accessed by the Aspose.Cells API. Let us discuss this matter with the product team to devise a troubleshooting mechanism for this scenario. We will get back after consultation.

Hi again,


You haven’t confirmed that both of your applications (test & main apps) are running on same machine and exhibit different behavior. Could you please confirm this along with any differences that you could find in application settings? Once you confirm this, we will provide you a debug assembly that could allow us to log information regarding the font substitution and hopefully we will be able to pin point the problem cause.

Thank you for your continues support in evaluating this scenario.

Hi Babar,

Yes, both applications are running on the same machine. (This odd behavior occurs on my own laptop, as well as on the production server, too.)

I’ll review the web.configs this morning and will let you know if I can spot anything that might be relevant.

Hi Michael,


Thank you for the confirmation. We will be looking forward to the web app settings for any differences across the two applications. Moreover, it is advised to set the font directory before creating any objects from the Aspose.Cells APIs so please check if the relevant statements are at the very start of your application.

That being said, I have made a formal request to the product team to provide a debug assembly to record the events that may allow us to pin point the problem cause. The ticket Id for the your future reference is CELLSNET-43823.