How can I solve an issue with Windows Fonts on Linux OS?

I’m trying to read Onenote file but I got this exception
Caused by: class com.aspose.note.system.exceptions.ArgumentException: FontFamily ‘Serif’ not found
Parameter name: Serif

But on Windows machine it works fine.

@aaukhatov,

Apparently, the issue seems related to missing fonts. Please install the underlying font(s) using .ttf file(s) on linux os and then give it a try a again, it should work fine.

Also, Could you please share details against the following queries:

  1. Which version of Aspose.Note for Java you are using?
  2. The exception says that there is no ‘Serif’ font. That is strange: by docs ‘Serif’ font is a logical font and must be present on the machine(refer to Font (Java Platform SE 8 )). Moreover, please share your complete environment details: e.g., your used linux distribution, version, Java version, etc.

The above details will help us evaluate your issue precisely on our end.

aspose-note:21.11
I use Mac OS 12.0.1 as dev env.
I customized the env var JAVA_FONTS with fonts from Windows. But it doesn’t help me

Another confusing thing is this exception has occurred even I create an instance of class com.aspose.note.Document. Without any content.
Why aspose lib force using strange fonts?

@aaukhatov,

Thanks for sharing the environment details.

Could you also share the complete stacktrace, this might help. Also, did you try your scenario/case on some other linux machine and you get the same issue?

    try {
        DocumentFontsSubsystem df = new DocumentFontsSubsystem();
        df.loadFontsFromFolder("/Users/artur/ms-fonts");
        df.addFontSubstitution("Serif", "SansSerif");
    } catch (IOException e) {
        e.printStackTrace();
    }

Exception in thread “main” java.lang.ExceptionInInitializerError
at com.aspose.note.fonts.FontsSubsystem.getSystemDefaultFont(Unknown Source)
at com.aspose.note.fonts.DocumentFontsSubsystem.(Unknown Source)
at com.aspose.note.fonts.DocumentFontsSubsystem.(Unknown Source)
at com.cloudally.App.main(App.java:35)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.aspose.note.internal.a.dd.g(Unknown Source)
at com.aspose.note.internal.a.dd.(Unknown Source)
… 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
… 6 more
Caused by: java.lang.ExceptionInInitializerError
at com.aspose.note.fonts.b.a(Unknown Source)
at com.aspose.note.fonts.b.(Unknown Source)
at com.aspose.note.fonts.a.(Unknown Source)
… 10 more
Caused by: class com.aspose.note.system.exceptions.ArgumentException: FontFamily ‘Serif’ not found
Parameter name: Serif
com.aspose.note.internal.as.k.(Unknown Source)
com.aspose.note.internal.as.k.(Unknown Source)
com.aspose.note.internal.as.k.(Unknown Source)
com.aspose.note.internal.as.k.(Unknown Source)
com.aspose.note.fonts.b.a(Unknown Source)
com.aspose.note.fonts.b.(Unknown Source)
com.aspose.note.fonts.a.(Unknown Source)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.aspose.note.internal.a.dd.g(Unknown Source)
com.aspose.note.internal.a.dd.(Unknown Source)
com.aspose.note.fonts.FontsSubsystem.getSystemDefaultFont(Unknown Source)
com.aspose.note.fonts.DocumentFontsSubsystem.(Unknown Source)
com.aspose.note.fonts.DocumentFontsSubsystem.(Unknown Source)
com.cloudally.App.main(App.java:35)
at com.aspose.note.internal.as.k.(Unknown Source)
at com.aspose.note.internal.as.k.(Unknown Source)
at com.aspose.note.internal.as.k.(Unknown Source)
at com.aspose.note.internal.as.k.(Unknown Source)
… 13 more

@aaukhatov,

Thanks for sharing the complete stacktrace.

We have logged an investigation ticket with an id “NOTEJAVA-1063” for your issue. We will look into it and analyze your issue in details. Once we have an update on it, we will let you know here.

By the way, did you try your scenario/case on some other MAC/linux machine and you still get the same issue?

Actually not. I’ve tested it on a different laptop, there it works as default without any exceptions.
But I have similar issues with fonts again when I’m reading/converting the OneNote file.

Java provides two approaches to set an extra fonts directory.
Program arg:

-Dappendedfontpath

Environment var:

JAVA_FONTS

But none of them help me. I still get an error with fonts. I have all fonts from Windows OS in my local directory.

@aaukhatov,

It looks like a configuration issue on your end, so you should figure it out accordingly for your environment. You may browse internet to find relevant topics for your reference (e.g. see the topic on how to manage fonts on linux). Could you please put all font files into the default fonts directory of your os and give it a try again if you still find the issue?

Okay, I figure out how to set extra fonts for Java
It requires to set $JAVA_HOME/jre/lib/fonts/fallback/
Then I got Windows fonts, but not all fonts from Windows are TrueTypeFont. I mean I’m still getting this error.
How can I use none TrueType fonts in aspose lib?

@aaukhatov,

Aspose.Note uses true type fonts for rendering, other types of fonts are not supported.

Hi.
I got this exception after using MS Windows Fonts.

    Exception in thread "main" class com.aspose.note.system.exceptions.ArgumentNullException: Value cannot be null.
    Parameter name: trueTypeFont
    com.aspose.note.internal.A.c.<init>(Unknown Source)
    com.aspose.note.internal.A.c.<init>(Unknown Source)
    com.aspose.note.cy.b(Unknown Source)
    com.aspose.note.cy.a(Unknown Source)
    com.aspose.note.ak.a(Unknown Source)
    com.aspose.note.ak.a(Unknown Source)
    com.aspose.note.ak.a(Unknown Source)
    com.aspose.note.ak.visitTitleStart(Unknown Source)
    com.aspose.note.Title.accept(Unknown Source)
    com.aspose.note.Page.accept(Unknown Source)
    com.aspose.note.cg.a(Unknown Source)
    com.aspose.note.cg.a(Unknown Source)
    com.aspose.note.cg.a(Unknown Source)
    com.aspose.note.V.a(Unknown Source)
    com.aspose.note.r.a(Unknown Source)
    com.aspose.note.r.b(Unknown Source)
    com.aspose.note.ao.d(Unknown Source)
    com.aspose.note.r.a(Unknown Source)
    com.aspose.note.Document.save(Unknown Source)
    com.cloudally.App.main(App.java:36)
    	at com.aspose.note.internal.A.c.<init>(Unknown Source)
    	at com.aspose.note.internal.A.c.<init>(Unknown Source)
    	at com.aspose.note.cy.b(Unknown Source)
    	at com.aspose.note.cy.a(Unknown Source)
    	at com.aspose.note.ak.a(Unknown Source)
    	at com.aspose.note.ak.a(Unknown Source)
    	at com.aspose.note.ak.a(Unknown Source)
    	at com.aspose.note.ak.visitTitleStart(Unknown Source)
    	at com.aspose.note.Title.accept(Unknown Source)
    	at com.aspose.note.Page.accept(Unknown Source)
    	at com.aspose.note.cg.a(Unknown Source)
    	at com.aspose.note.cg.a(Unknown Source)
    	at com.aspose.note.cg.a(Unknown Source)
    	at com.aspose.note.V.a(Unknown Source)
    	at com.aspose.note.r.a(Unknown Source)
    	at com.aspose.note.r.b(Unknown Source)
    	at com.aspose.note.ao.d(Unknown Source)
    	at com.aspose.note.r.a(Unknown Source)
    	at com.aspose.note.Document.save(Unknown Source)
    	at com.cloudally.App.main(App.java:36)

@Amjad_Sahi can you ignore missing fonts? I don’t need to render a file. I should just convert a file and upload it.

@aaukhatov,

If a OneNote document uses a font that is not available on the machine then you can specify to substitute it by another widely used font. See the document with example codes for your reference.

It’s not my case. I wouldn’t like substitute fonts.
I would like convert.

@aaukhatov,

We are sorry but still we could not evaluate your issue precisely since such an issue is not occurred on our end. By the way as we asked earlier, did you try your scenario/case on some other machine (MAC/linux) and you still get the same issue?

Okay) I’ll prepare it

@aaukhatov,

Please take your time to evaluate the issue on different machines.

@aaukhatov,

We also investigated your original issue. We run the sample app under MacOS Monterey + openjdk with latest version of Aspose.Note for Java. We found no issues.

Could you please provide us more information:

  • What’s Java implementation you use and its exact version?
  • Are there any special settings for OS/Java that can affect font’s processing (we use java.awt package)?
  1. We made a fix based on analysis of provided stack trace. We also attached this build: aspose-note-22.1.1-jdk17.jar. Can you try this custom build and let us know your feedback/result?

Hey @Amjad_Sahi
This patch of the library doesn’t help me.
I attached my One Note files and a small java project where I tried to read One Note.
Please, take a look at
OneNoteFiles.zip (6.6 KB)
one-note-java.zip (9.9 MB)

I’m waiting for feedback.

Mac OS Monterey 12.4
openjdk version “17.0.2” 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Locale.setDefault(new Locale(“en-us”));

Exception in thread "main" class com.aspose.note.system.exceptions.ArgumentNullException: Value cannot be null.
Parameter name: trueTypeFont
com.aspose.note.internal.A.c.<init>(Unknown Source)
com.aspose.note.internal.A.c.<init>(Unknown Source)
com.aspose.note.cy.b(Unknown Source)
com.aspose.note.cy.a(Unknown Source)
com.aspose.note.ak.a(Unknown Source)
com.aspose.note.ak.a(Unknown Source)
com.aspose.note.ak.a(Unknown Source)
com.aspose.note.ak.visitTitleStart(Unknown Source)
com.aspose.note.Title.accept(Unknown Source)
com.aspose.note.Page.accept(Unknown Source)
com.aspose.note.cg.a(Unknown Source)
com.aspose.note.cg.a(Unknown Source)
com.aspose.note.cg.a(Unknown Source)
com.aspose.note.V.a(Unknown Source)
com.aspose.note.r.a(Unknown Source)
com.aspose.note.r.b(Unknown Source)
com.aspose.note.ao.d(Unknown Source)
com.aspose.note.r.a(Unknown Source)
com.aspose.note.Document.save(Unknown Source)