I run on linux, and did not encounter this problem in 25.4.
ibm-japan.docx (58.0 KB)
@nicolasmartel Could you please provide a simple code that will allow us to reproduce the problem? We will check the issue and provide you more information.
I ran the same upload by running the java process on my mac, and it’s not happening the error, only in Linux as far as I can tell.
package com.company.document.converter.aspose;
import com.aspose.words.Document;
import com.aspose.words.FieldUpdateCultureSource;
import com.aspose.words.FontInfo;
import com.aspose.words.FontInfoCollection;
import com.aspose.words.FontSettings;
import com.aspose.words.IWarningCallback;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.aspose.words.WarningInfo;
import com.aspose.words.WarningType;
import com.company.document.converter.DocumentConverter;
import com.company.platform.logs.lazy.logging.OspLazyLoggerFactory;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Set;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.format;
@Component
public class AsposeDocumentConverter implements DocumentConverter {
private static final OspLazyLoggerFactory Logger = new OspLazyLoggerFactory(AsposeDocumentConverter.class.getName());
private final Set<String> supportedFileExtensions = newHashSet("doc", "docx", "rtf", "txt");
private final License license = new License();
@Value("${oss.converter.printFonts}") private boolean printFonts = false;
@Value("${oss.converter.hideDocumentName}") private boolean hideDocumentName = false;
@Autowired
public AsposeDocumentConverter(
@Value("${esl.converter.aspose.license}") String licenseLocation,
@Value("${esl.converter.aspose.font.directories}") String fontDirectories,
@Value("${esl.converter.aspose.odt.supported}") boolean supportODT,
@Value("${esl.converter.aspose.font.load-noto-fallback-settings}") boolean loadNotoFallbackSettings,
@Value("${esl.converter.aspose.font.load-linux-table-substitution}") boolean loadLinuxTableSubstitution) {
Logger.atInfo().log("Attempting to read Aspose license file from [" + licenseLocation + "]");
try {
Resource licenseFile = new DefaultResourceLoader().getResource(licenseLocation);
license.setLicense(licenseFile.getInputStream());
Logger.atInfo().log("Aspose license has been read successfully");
} catch (Exception e) {
Logger.atWarn().log("Aspose license could not be initialized. Document conversion won't work.");
throw new RuntimeException(e);
}
configureFonts(fontDirectories, loadNotoFallbackSettings, loadLinuxTableSubstitution);
if (supportODT) {
supportedFileExtensions.add("odt");
}
}
private void configureFonts(String fontDirectories, boolean loadNotoFallbackSettings, boolean loadLinuxTableSubstitution) {
FontSettings defaultInstance = FontSettings.getDefaultInstance();
// https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/
if (loadNotoFallbackSettings) {
try {
Logger.atInfo().log("Loading Noto fallback settings");
defaultInstance.getFallbackSettings().loadNotoFallbackSettings();
} catch (Exception e) {
Logger.atWarn().log("Failed to load Noto fallback settings - " + e.getMessage());
}
}
if (loadLinuxTableSubstitution) {
try {
Logger.atInfo().log("Loading Linux Table Substitution settings");
defaultInstance.getSubstitutionSettings().getFontConfigSubstitution().setEnabled(true);
defaultInstance.getSubstitutionSettings().getTableSubstitution().loadLinuxSettings();
// Asian characters full substitution
String fontCJKDefault = "Go Noto CJKCore";
// Add fonts to this list as needed
String fontListCJK = "MS Mincho, MS Gothic, MS 明朝, MS ゴシック, MS PGothic, MS UI Gothic, SimSun, Microsoft JhengHei, Microsoft YaHei, Arial Unicode MS, Dotum, DotumChe, Gulim, GulimChe, SimSun, SimSun-ExtB, NSimSun, MingLiU, MingLiU-ExtB, MingLiU_HKSCS, MingLiU_HKSCS-ExtB, PMingLiU, PMingLiU-ExtB, Batang, BatangChe, Gungush, GungushChe, Malgun Gothic, DengXian";
Arrays.stream(fontListCJK.split(", ")).forEach(fontName -> defaultInstance.getSubstitutionSettings().getTableSubstitution().setSubstitutes(fontName, fontCJKDefault));
// Calibri based fonts
String fontCarlito = "Carlito";
String fontListCalibri = "Calibri, Calibri Light";
Arrays.stream(fontListCalibri.split(", ")).forEach(fontName -> defaultInstance.getSubstitutionSettings().getTableSubstitution().setSubstitutes(fontName, fontCarlito));
// Cambria based fonts
String fontCaladea = "Caladea";
String fontListCambria = "Cambria, Cambria Math";
Arrays.stream(fontListCambria.split(", ")).forEach(fontName -> defaultInstance.getSubstitutionSettings().getTableSubstitution().setSubstitutes(fontName, fontCaladea));
// Extra font substitution
defaultInstance.getSubstitutionSettings().getTableSubstitution().setSubstitutes("Symbol", "DejaVu Sans Mono");
} catch (Exception e) {
Logger.atWarn().log("Failed to load Linux Table Substitution settings - " + e.getMessage());
}
}
if (isNullOrEmpty(fontDirectories)) {
Logger.atInfo().log("No additional font directories were specified, using the Aspose default font directory searching algorithm");
return;
}
Arrays.stream(fontDirectories.split(",")).forEach(fontDir -> defaultInstance.setFontsFolder(fontDir, true));
}
private void printDocumentFontsIfEnabled(Document doc) {
if (printFonts) {
try {
Logger.atInfo().log("Printing all fonts found in document");
FontInfoCollection fonts = doc.getFontInfos();
for (FontInfo font : fonts) {
MDC.put("font-name", font.getName());
MDC.put("font-alt-name", font.getAltName());
MDC.put("font-true-type", format("%b", font.isTrueType()));
Logger.atInfo().log("Printing font context");
}
} finally {
MDC.remove("font-name");
MDC.remove("font-alt-name");
MDC.remove("font-true-type");
}
}
}
public String censureDocumentName(String name) {
String baseName = FilenameUtils.getBaseName(name);
String extension = FilenameUtils.getExtension(name);
return baseName.replaceAll(".", "*") + "." + extension;
}
public byte[] convert(String name, InputStream document) {
String loggableName = hideDocumentName ? censureDocumentName(name) : name;
Logger.atInfo().log("AsposeDocumentConverter.convert() called for document named [" + loggableName + "]");
try {
Document asposeDoc = new Document(document);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
printDocumentFontsIfEnabled(asposeDoc);
asposeDoc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
asposeDoc.setWarningCallback(new FontWarningHandler(loggableName));
asposeDoc.save(bytes, SaveFormat.PDF);
return bytes.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public boolean supports(String fileExtension) {
return supportedFileExtensions.contains(fileExtension);
}
private static class FontWarningHandler implements IWarningCallback {
private final String documentName;
FontWarningHandler(String documentName) {
this.documentName = documentName;
}
public void warning(WarningInfo warning) {
if (warning.getWarningType() == WarningType.FONT_SUBSTITUTION) {
Logger.atInfo().log("Font substitution in document [" + documentName + "]: " + warning.getDescription());
}
}
}
}
I have investigated your issue but was unable to reproduce the error on my end. I used the latest version of Aspose.Words for Java 25.5 and Ubuntu 24.04.2. Please provide more detailed information about the operating system you are using, as well as the Java version.
Amzonlinux 2023 and java 21
@nicolasmartel
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): WORDSJAVA-3100
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.