@blusynergy
We would like to share with you that we have investigated your issue and found that the reason of exception was absence of basic MS Fonts on the Linux Machine. It is recommended to install all basic MS Fonts before performing operation using Aspose.PDF for Java. In your particular case, the Times New Roman font is necessary because this font was not embedded in the PDF document and still used in it. Please see attached image:
Structure.png (66.3 KB)
Also, please note that every font has own metrics (symbol height, weight, interval, etc.) and the structure of you PDF document contains words as separate characters or group of characters which is reason for overlapping. This cannot be handled without a suitable font because, each new group starts in the absolute position and because of different characters width and intervals, symbols can be overlapped.
There are two ways to fix the conversion:
- Install msttcorefonts package for CentOS/Linux
- Copy required fonts and set path to the font directory by method:
FontRepository.addLocalFontPath("path_to_fonts");
Also, you can use notification to know if any font was substituted because of absent font and handle default font used. Please add following code before conversion:
CustomFontSubstitutionBase subst = new CustomFontSubstitutionBase() {
public boolean trySubstitute(CustomFontSubstitutionBase.OriginalFontSpecification originalFontSpecification, /*out*/ com.aspose.pdf.Font[] substitutionFont) {
System.out.println("Warning: Font " + originalFontSpecification.getOriginalFontName() + " is try to be substituted");
if (!originalFontSpecification.isEmbedded()) {
try {
Font fSrcInRepository = FontRepository.findFont(originalFontSpecification.getOriginalFontName());
if (fSrcInRepository==null){
System.out.println("font not found");
return false;
// substitutionFont[0] = FontRepository.openFont("/path_to_font/times.ttf");//or use default specified font
// System.out.println("Font " + originalFontSpecification.getOriginalFontName()
// + " was substituted with another font -> " + substitutionFont[0].getFontName());
}else {
substitutionFont[0] = fSrcInRepository;
}
} catch (FontNotFoundException e) {
System.out.println("font not found");
return false;
// substitutionFont[0] = FontRepository.openFont("/path_to_font/times.ttf");//or use default specified font
// System.out.println("Font " + originalFontSpecification.getOriginalFontName()
// + " was substituted with another font -> " + substitutionFont[0].getFontName());
}
return true;
} else {
return super.trySubstitute(originalFontSpecification, substitutionFont);
}
}};
FontRepository.getSubstitutions().add(subst);
We really hope that above details would help resolving your issue. In case you still face any issue, please feel free to let us know.