FONT issue in generated PDF

Hello,
In our program aspose-words-18.2-jdk16.jar is used to generate pdf files. There is a letter template in .doc format which has a line with OCR A Extended font.
When it is saved as PDF this font is changed to Ming Li U. We have OCR A Extended installed on the server, but that does not work.
Here is part of the code to save as pdf. What should we do to keep the OCR A Extended font? Our client needs that for their letter.

ByteArrayInputStream bdyTmplStream = new ByteArrayInputStream(letterContent);
Document tmplDoc = new Document(bdyTmplStream);
ByteArrayOutputStream mergedOutputStream = new ByteArrayOutputStream();
PdfSaveOptions opt = new PdfSaveOptions();
opt.setExportDocumentStructure(true);
opt.setEmbedFullFonts(true);
if(fontDir != null && (new File(fontDir)).isDirectory()){
  FontSettings.getDefaultInstance().setFontsFolder(fontDir, true);
}
tmplDoc.save(mergedOutputStream, opt);

Thanks,
Farnaz

@farnaz2021

To ensure that the OCR A Extended font is preserved when generating PDF files from a .doc template using Aspose.Words, you can follow these steps:

  1. Check Font Installation: First, confirm that the OCR A Extended font is correctly installed on the server where the application is running. Sometimes, the font may not be recognized due to installation issues.

  2. Set Font Directory: In your code, you are already setting the font directory using FontSettings.getDefaultInstance().setFontsFolder(fontDir, true);. Make sure that the fontDir variable points to the correct directory where the OCR A Extended font is located.

  3. Embed Full Fonts: You are using the PdfSaveOptions and setting opt.setEmbedFullFonts(true);. This is correct as it ensures that all fonts used in the document are embedded in the PDF. This is crucial for maintaining the appearance of the document.

  4. Use the Correct Save Options: Ensure that you are using the correct save options when saving the document. Here’s a sample code snippet that incorporates these suggestions:

    ByteArrayInputStream bdyTmplStream = new ByteArrayInputStream(letterContent);
    Document tmplDoc = new Document(bdyTmplStream);
    ByteArrayOutputStream mergedOutputStream = new ByteArrayOutputStream();
    PdfSaveOptions opt = new PdfSaveOptions();
    opt.setExportDocumentStructure(true);
    opt.setEmbedFullFonts(true); // Ensure all fonts are embedded
    
    // Set the font directory if it is not null and is a directory
    if (fontDir != null && (new File(fontDir)).isDirectory()) {
        FontSettings.getDefaultInstance().setFontsFolder(fontDir, true);
    }
    
    // Save the document as PDF
    tmplDoc.save(mergedOutputStream, opt);
    
  5. Test with Different Fonts: If the issue persists, try testing with a different font to see if the problem is specific to the OCR A Extended font. This can help isolate the issue.

By following these steps, you should be able to maintain the OCR A Extended font in the generated PDF. If the problem continues, consider checking for any specific font licensing issues or compatibility problems with the Aspose.Words version you are using.

If you need further assistance, feel free to ask!

Sources:
[1]: Embed Fonts in PDF Document | Aspose.Words Document Processing API

Thanks for the response. We have done all these, but still have the issue. I tested with another font (Impact font) and that worked fine. What else do you suggest to try?

@farnaz2021 Could you please attach your input and output documents here for testing? We will check conversion on our side and provide you more information.

The problem on your side might occur because the fonts used the documents are not available in the environment where documents are converted. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

I have uploaded the template document and generated pdf file to the bellow link. Also you can found the font used OCRAEXT.TTF in that link. This font in installed in our sever where the pdf is generated.
Please Note → The line with the font issue is the last line of page 1 of the document.