We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception "com.aspose.cells.CellsException: Cannot find required font" on Linux in Java

Hello,


I’m writing an application using the Java Aspose components. Specifically, the Excel component. I am writing this on Ubuntu Linux, with no X-Windows installed - it’s just a server.

When saving the opened Excel to a PDF, I get an error saying it cannot find a specified font. Is there something I need to install to make these fonts available, or to have Aspose degrade to a known font?

Thank you. Here is the stack trace:

Exception in thread “main” com.aspose.cells.CellsException: Cannot find required font defination[Family:Calibri, Style:0]. Please specify font path.
at com.aspose.cells.yc.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at managers.file.ExcelManager.GetPDF(ExcelManager.java:40)
at managers.file.RoutingManager.Route(RoutingManager.java:31)
at managers.file.RoutingManager.GetPDF(RoutingManager.java:22)
at Converter.main(Converter.java:27)

Hi,

Well, you may try to simply copy the font files from Windows
operating system i.e. “C:\WINDOWS\Fonts\” to Linux operating system on
path e.g “/home/usr/test/winfont”.

Now, pass this path as string to method of SaveOptions mentioned below:
e.g
book.getSaveOptions().setFontPath(new String[]{"/home/usr/test/winfont"});

Please also see.

If the font file of one font that used by excel file cannot be found, we will try to use Arial font firstly if it exists. If Arial font file cannot be found, we will use font files defined under <java.home>/lib/fonts which exist for JDK1.4 and later versions.

Currently
we does not support users to set alternative font. The only alternative
font user can specify is the default render font(by SaveOptions.setDefaultRenderFont(String)). This font is designed for the situation that cell’s content includes both ascii and unicode characters and specified font for this cell cannot render the unicode characters. If user needs, we can use this default render font firstly to replace the fonts that cannot be found.


Arial would be fine. Where does it look for the Arial font, do you know? I’ll just start by trying to get it to render using Arial, and then I’ll try to setup custom font paths if I can get that to work.


Thanks

I’m using Ubuntu, and I just installed a package that is supposed to contain a lot of Windows fonts. I see that Arial is included. The location that it installed these fonts to is: /usr/share/fonts/truetype/msttcorefonts


Is that a path that Aspose already checks? I tried running it, and it still cannot locate the Arial font.

Hi,

This is just an example, Aspose will look for a font in the directory you specified.

Please set the path of your font(s) using the setFontPath method.

e.g
book.getSaveOptions().setFontPath(new String[]{"/home/usr/test/winfont"});

mshakeel.faiz:
Hi,

This is just an example, Aspose will look for a font in the directory you specified.

Please set the path of your font(s) using the setFontPath method.

e.g
book.getSaveOptions().setFontPath(new String[]{"/home/usr/test/winfont"});

I have already tried that exact function. It does not exist. It's not in the documentation, either.

Are you sure this is the correct method?

Thanks

I should mention my version of Java:


λ ~/projects/java-converter/src/ master* java -version
java version "1.7.0_147-icedtea"
OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-0ubuntu0.11.10.1)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

Is this version compatible?

Hi,

Please try this and let me know if it works for you. Modify it according to your system environment.

//Add this line**//
CellsHelper.setFontDir(“c:\windows\fonts”);

Ok. How do I acquire the CellsHelper reference? I looked at the documentation for Workbook and Worksheet. Neither seem to have a documented method that gives me the CellsHelper instance.


Thyanks

Hi,


You don’t need to instantiate the CellsHelper class, its methods are static and can be used directly, see the sample line of code pasted by Shakeel Faiz in his previous reply.

Thank you.

Awesome. That works. Thanks a ton!