Set Custom Fonts Folder & Convert Word DOCX to PDF using Java on Windows Server

Hi Team,

we are using Aspose Java API to convert files to PDF. We have seen an Issue with font getting changed for word Files while converting to pdf. we are running this conversion on windows server which doesnt have word Installed. Please find the attached document for font change screenshots. Please suggest way to fix this Issue.

Aspose_Fonts.docx (27.2 KB)

@karthik13,

Have you tried the latest (21.7) version of Aspose.Words for Java on your end? In case the problem still remains, then please compress the following resources into ZIP format and upload the .zip file here for testing:

  • Your simplified source Word DOCX document you’re getting this problem with
  • Font files used in above Word document
  • Aspose.Words for Java 21.7 generated PDF file showing the undesired behavior

We will then investigate the issue on our end and provide you more information.

Hi Hafeez,

Below is our observation.

  1. Word file converted to PDF in windows server has font changed.
  2. Same word file converted to PDF in local machine has same font (No Issue)
  3. Windows Server doesnt have office Installed in it.

Please suggest.

Thank You
Karthik

@karthik13,

Please first check which fonts are being used in the source Word document. Then please copy the latest versions of those required font files from Windows 10 machine into a separate folder inside Windows Server machine and try running the following code of latest 21.7 version of Aspose.Words for Java:

Document doc = new Document("C:\\Temp\\word.docx");

FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, myDir + "CustomFonts/");
doc.setFontSettings(fontSettings);

doc.save("C:\\Temp\\awjava21.7.pdf");

private static void addFontFolder(FontSettings fontSettings, String folder)
{
    FontSourceBase[] fontSourceBases = fontSettings.getFontsSources();
    FontSourceBase[] newFontSourceBases = new FontSourceBase[fontSourceBases.length + 1];
    System.arraycopy(fontSourceBases, 0, newFontSourceBases, 0, fontSourceBases.length);
    newFontSourceBases[newFontSourceBases.length - 1] = new FolderFontSource(folder, true);
    fontSettings.setFontsSources(newFontSourceBases);
}

Also, please refer to the following sections of documentation: