Pdf font has been changed by using FontRepository.LoadFonts

Hi,

I look through “FontRepository.LoadFonts” document, it says that load system fonts and standard pdf font. But my pdf font is different before and after the usage method.

My Html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <style type="text/css">
	body {
	  font-family: 'Arial Unicode MS';
	  font-size: 16px;
	}
      </style>
    </head>

    <body>
      test123
    </body>
</html>

my code:

String out = "C:\\Users\\xxx\\Desktop\\1.pdf";
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
Document document = new Document(new FileInputStream("C:\\Users\\xxx\\Desktop\\123.html"), htmlLoadOptions);
document.save(out);

// Load PDF document
Document pdfDocument = new Document(out);
Font[] allFonts = pdfDocument.getFontUtilities().getAllFonts();
for (Font font : allFonts) {
    System.out.println(font.getFontName());
}

the font result is:

TimesNewRoman
Arial

when I add

FontRepository.loadFonts();

the result is

ArialUnicodeMS
Arial

Why pdf font has been changed? Based on the api document, FontRepository.loadFonts() only load system font, why it impact pdf font?

Thanks

@lucy.hq

We used the same code snippet in our environment to test the scenario with Aspose.PDF for Java 21.7 and we got the correct results. The output was “ArialUnicodeMS” in both cases i.e. with and without calling FontRepository.loadFonts() method. Can you please share that in which path your system fonts are installed? Also, please make sure to use the latest version of the API and let us know about your feedback.

hi,
Thank you for reply so quickly. I’m using 21.7 and my system fonts are install under C:\Windows\Fonts

@lucy.hq

We were unable to reproduce the similar behavior of the API on our side. Would you please share the below information so that we can log an investigation ticket to further analyze it?

  • Your complete environment details e.g. OS Name and Version, JDK Version, Application Type
  • Output PDF documents generated at your end with and without calling FontRepository.loadFonts();
  1. Windows 10 version:20H2
    JDK version:14.0.2
    application: intellj idea
  2. attach pdf without calling FontRepository.loadFonts();
    1.pdf (62.5 KB)

@lucy.hq

It seems like you are using Aspose.PDF without any license. Can you please try to use the API with a permanent or 30-days free temporary license and share your feedback with us? There could be a chance that those different fonts are used by the API for evaluation watermark in the output PDF.