Free Support Forum - aspose.com

Java Code to Convert MSG with Foreign Chinese Characters to PDF on Ubuntu | MS JhengHei Font | Aspose.Email & Aspose.Words

Hello,

I have an issue when trying to convert an msg file that contains chinese characters to a pdf using Aspose.words for java running on ubuntu. The msg file contains characters that are in the Microsoft Jhenghei font family and it doesn’t appear that aspose has a mapping for this font family since they get rendered out as boxes. I added a variety of fonts and specified a font folder and that did not seem to make a difference.

Is there somewhere to get the default mappings of languages that aspose supports by defaults? Is there not a default fallback for this Microsoft font?

image.png (4.6 KB)

image.png (801 Bytes)

@nduncan,

Please ZIP and upload your source MSG file containing the Chinese characters and Aspose.Words generated PDF file showing the undesired behavior here for testing. We will then investigate the issue on our end and provide you more information.

Please see attached files. chinese test.zip (48.7 KB)

Please see attached files.

chinese test.zip (48.7 KB)

@nduncan,

Please install the following Font files on your Ubuntu machine. You can copy these fonts from Windows 10 machine:

  • Calibri
  • MS Gothic
  • Microsoft JhengHei

Please refer to the following sections of documentation:

We do not have a license to be able to transfer the fonts from a windows machine to a linux machine.

@nduncan,

You can search for free alternative fonts on web or change the font of text using Aspose.Words.

Document doc = new Document("C:\\Temp\\input.mhtml"); // or load from stream
FontChanger changer = new FontChanger();
doc.accept(changer);
doc.save("C:\\Temp\\awjava-21.1.docx");

public static class FontChanger extends DocumentVisitor {
    ///
    /// Called when a FieldEnd node is encountered in the document.
    ///
    public int VisitFieldEnd(final FieldEnd fieldEnd) {
        //Simply change font name
        ResetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a FieldSeparator node is encountered in the document.
    ///
    public int VisitFieldSeparator(final FieldSeparator fieldSeparator) {
        ResetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a FieldStart node is encountered in the document.
    ///
    public int VisitFieldStart(final FieldStart fieldStart) {
        ResetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a Footnote end is encountered in the document.
    ///
    public int VisitFootnoteEnd(final Footnote footnote) {
        ResetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a FormField node is encountered in the document.
    ///
    public int VisitFormField(final FormField formField) {
        ResetFont(formField.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a Paragraph end is encountered in the document.
    ///
    public int VisitParagraphEnd(final Paragraph paragraph) {
        ResetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a Run node is encountered in the document.
    ///
    public int visitRun(final Run run) {
        ResetFont(run.getFont());
        return VisitorAction.CONTINUE;
    }

    ///
    /// Called when a SpecialChar is encountered in the document.
    ///
    public int VisitSpecialChar(final SpecialChar specialChar) {
        ResetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
    }

    private void ResetFont(Font font) {
        font.setName(mNewFontName);
        // font.setSize(mNewFontSize);
    }

    private String mNewFontName = "Calibri"; // or specify some other
    // private double mNewFontSize = 19.0;
}