Aspose.Words native libs cannot be loaded when application is running from Linux-x64

Hi Team,

Text is Moved to Next Line after DOCX to PDF Conversion using Java when application is running in Linux, I’m using aspose-words version is 22.7.
I raised an issue for this earlier for your info ( Alignment is not properly rendering in Output pdf )
Now, I tried adding this line of code

doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());   

and ran the application then I’m getting the issue as below specified:

aspose.Words native libs cannot be loaded.  /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: failed to map segment from shared object: Operation not permitted
Aspose.Words native libs cannot be loaded.  /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: failed to map segment from shared object: Operation not permitted
Aspose.Words native libs cannot be loaded.  /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: /tmp/AsposeNative/Shaping.Harfbuzz/1689154276976/libharfbuzz-shaping-engine-dll.so: failed to map segment from shared object: Operation not permitted
Jul 12, 2023 10:31:17 AM com.aspose.words.shaping.internal.zzZFK zzYSQ
SEVERE: 
java.lang.UnsatisfiedLinkError: 'long com.aspose.words.shaping.harfbuzz.HB.hb_font_create_from_data(byte[], int)'
@at com.aspose.words.shaping.harfbuzz.HB.hb_font_create_from_data(Native Method)
@at com.aspose.words.shaping.harfbuzz.zzGX.zzZvN(Unknown Source)
@at com.aspose.words.shaping.harfbuzz.zzGX.zzZ4P(Unknown Source)

Could you please guide me to move forward.

Regards,
Rakesh

@Rakesh_M For Windows platforms no additional efforts are required for installing HarfBuzz because Aspose.Words.Shaping.Harfbuzz already includes compiled HarfBuzz library.
For other systems, Aspose.Words.Shaping.Harfbuzz relies on already installed HarfBuzz library. For instance, many Linux-based systems have HarfBuzz installed system-wide by default. If not, there is usually a package available for installing via package manager.

Regarding layout issues on Linux. Most likely the problem occurs because fonts required for document rendering are not available in your Linux environment. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted . This might lead into the layout and appearance difference. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
Please try either installing or providing the fonts required to render the document. This should resolve the problem.

If after installing the required fonts, the problem still persist, please attach your source and output documents here for testing.

Hi,
could you please help the latest version of msttcorefonts to install in linux?

Regards,
Rakesh

@Rakesh_M You can install MS Core Fonts using the following command on Ubuntu:

sudo apt install ttf-mscorefonts-installer

Other distributions might have different package name.

It’s not ubuntu,
linux-x64.

@Rakesh_M What Linux distribution do you use?

RHEL.
and Microsoftt fonts are to installed in my linux box. msttcorefonts-2.5.1 is retired and not available in our repo
and i’m looking for latest version or any other way to install?

@Rakesh_M You can simply copy the required fonts into a folder in your environment and use this folder as four source for Aspose.Words:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/

Hi Team,
Provided font(Arial) in the template word document is not using to display in the Pdf document when we run the application from Linux.

It’ is using as Fanwood text in the pdf generated file.
I’m providing all the Arial fonts in the resources->fonts folder in my application.

Please find the attached sample files.
The code which i’m using was below specified:

FontSettings.getDefaultInstance().setFontsSources(
                new FontSourceBase[] { new FolderFontSource("fonts/", true) });

test-template_from-linux.docx (12.1 KB)

Could you please suggest?

Regards,
Rakesh

@Rakesh_M Fanwood font is the last resort font used by Aspose.Words when no other fonts are available in the environment where document is rendered. Please make sure the specified fonts folder is availabe and accessible by the application.
You can use the following code to get list of fonts available in the specified font sources:

Document doc = new Document("/temp/in.docx");

doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsSources(
    new FontSourceBase[] {
        new SystemFontSource(), // Search for fonts in the default system locations
        new FolderFontSource("/temp/fonts/", true) // Search for fonts in the specified folder
    });

// Print the fonts available in the sources specified in FontSettings
for (FontSourceBase fsb : doc.getFontSettings().getFontsSources())
{
    for (PhysicalFontInfo fontInfo : fsb.getAvailableFonts())
    {
        System.out.println("FontFamilyName : " + fontInfo.getFontFamilyName());
        System.out.println("FullFontName  : " + fontInfo.getFullFontName());
        System.out.println("Version  : " + fontInfo.getVersion());
        System.out.println("FilePath : " + fontInfo.getFilePath());
    }
    System.out.println("=========================");
}

doc.save("/temp/out.pdf");

I used the above code, but now it’s using this font DejaVuSans.
earlier it was using Fanwood font.
This is the code which i’m using ::

templateDoc.setFontSettings(new FontSettings());
templateDoc.getFontSettings().setFontsSources(
    new FontSourceBase[] { new SystemFontSource(), // Search for fonts in the default system locations
    new FolderFontSource("fonts/", true) // Search for fonts in the specified folder
});

NOTE:: fonts folder is available in resources folder of my application.

Please suggest.

@Rakesh_M You can use FontSourceBase.WarningCallback property to get notification when an issue is detected while loading fronts from the font source. For example try using the following code:

FontSourceBase source = new FolderFontSource("bad folder?", true);
source.WarningCallback = new WarningCallback();
IList<PhysicalFontInfo> fontInfos = source.GetAvailableFonts();
private class WarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine(info.Description);
    }
}

Output will be:

Error loading font from the folder “bad folder?”: Illegal characters in path.

Please, also try specifying full path to the fonts directory in your code.