An error occurs When calling FontRepository.addLocalFontPath()

Hello.
About local font load.

An error occurs When calling FontRepository.addLocalFontPath(“localFontPath”).
but, the parameter(“localFontPath”) passed fine…
*Error: StringIndexOutOfBoundsException

The jar file uses the aspose-pdf-19.2-jdk16.jar version.
The location of the font to be used is located in C:\font.
*An error also occurs when reading fonts in the C:\Windows\Fonts location provided by default in window.

The current development environment is a vdi(virtual desktop infrastructure) environment.
Is this related?

Please check this problem.
Thank you.

@jisu4717

Yes, the issue looks related to the specific environment. We tested in Windows OS and could not reproduce the issue. Can you please try using 23.7 version of the API and see if that raised the similar exception? We will log an investigation ticket and share the ID with you.

Hello.
This is emro ji-su.

Thank you for answer.
But, the issue is not solved.

As a result of checking, the default font C:\windows\fonts provided by Windows OS system is not being accessed.
*Folder files that I created separately can be accessed.

Could you please provide the code(logic) to access the Fonts of the window OS system?

Please check this issue.
Thank you.

@jisu4717

The API by default access the font from “C:\Windows\Fonts” directory in Windows and from “/usr/share/fonts/truetype/msttcorefonts” in Linux like operating system. If such directory is not present or not accessible, API throws an exception. In such case, you can define the fonts resources in the API where all fonts are located.

FontRepository.getSources().clear();
FontSource fs = new FileFontSource(dataDir  + "customfonts\\");
FontRepository.getSources().add(fs);

Furthermore, if such directories are present in the VDI environment, please make sure that your application is able to access these directories. In case issue still persists, please share some more details about the environment and we will investigate accordingly.

@asad.ali
Hello.
This is the emro ji-su.

Thank you for answer.

I cleared all FontRespository resources and code to directly access the directory where the font exists through FontSource.
But, the issue is not resolved.
I think I can access the custom font directory, but I can’t access C:\windows\Fonts.

Is the logic for accessing fonts provided by Windows related to lines 298 to 299 rows of FontRepository?

298 : com.aspose.pdf.internal.l25v.lh.lb().lI(var6, true);
299 : le.lb().lI(var6, true);

It seems that an error occurs while passing these two lines.

What I want is code to access the fonts(C:\Windows\Fonts) provided by window and code to check whether the fonts exist.

Please check this issue.
Thank you.

As shared earlier, you do not need specific code to search this directory as API does it by default. Furthermore, you can add this source directory using the same code snippet which was shared earlier.

Can you please share the complete error stack information and more details about the VDI environment? We will log an investigation ticket and share the ID with you.

@asad.ali

Hello.
This is emro ji-su.

The vdi environment info is as follows.

  • OS: Windows
  • version: Windows 10 Enterprise LTSC
  • RAM: 64 bit, x64

The location where the error occurs is FontRepository.addLocalFontPath(“fontPath”).
It seems that an error occurs in some code inside the function (addLocalFontPath).

The error stack is as follows.
nested exception is class com.aspose.pdf.internal.ms.System.lk: Value cannot be null.
Parameter name: path1
com.aspose.pdf.internal.ms.System.IO.l1y.lf(Unknown Source)
com.aspose.pdf.FontRepository.lI(Unknown Source)
com.aspose.pdf.FontRepository.getLocalFontPaths(Unknown Source)
com.aspose.pdf.FontRepository.lI(Unknown Source)
com.aspose.pdf.FontRepository.addLocalFontPath(Unknown Source)

Please check the issue.
Thank you.

@jisu4717

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-43096

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.