Korean language issue while converting word to pdf

Hello, I am having a problem with Korean language font, when converting a word file into a pdf, it works for any other languages but for the Korean it renders only the hardcoded text, for the rest I can see only small empty squares. Could you please help me about that? Please see the code below:

 public async Task<MemoryStream> GenerateDocument(string jsonData)
 {

     var wordService = _documentCreatorFactory.CreateDocumentService(OutputFormatEnum.Word);

     var wordByteStream = await wordService.GenerateDocument(jsonData);

     await ApplyAsposeLicenseAsync();

     var document = new Document(wordByteStream);

     var builder = new DocumentBuilder(document);

     builder.Font.NameFarEast = "SimSun";
     builder.Font.LocaleIdFarEast = new CultureInfo("zh-CN", false).LCID;

     builder.Font.NameFarEast = "Malgun Gothic";
     builder.Font.LocaleIdFarEast = new CultureInfo("ko-KR", false).LCID;

     builder.Write("할인소비자가");

     using var pdfStream = new MemoryStream();

     document.Save(pdfStream, SaveFormat.Pdf);

     return pdfStream;
 }

@kubra1234

It seems you are experiencing issues with rendering Korean characters when converting a Word document to PDF using Aspose.Words. This problem often arises due to font substitution issues. Here are some steps you can take to resolve this:

  1. Ensure Proper Fonts are Installed: Make sure that the fonts you are using in your Word document are installed on the system where the conversion is taking place. For Korean characters, fonts like “Malgun Gothic” or “SimSun” should be available.

  2. Check for Font Substitution: You can implement a warning callback to check if any fonts are being substituted during the conversion process. This will help you identify if the required fonts are not being found. Here’s a code snippet to help you with that:

    Document doc = new Document(@"C:\\Temp\\Korean doc.docx");
    doc.WarningCallback = new WarningCallback();
    doc.Save(@"C:\\Temp\\out.pdf");
    
    private class WarningCallback : IWarningCallback {
        public void Warning(WarningInfo info) {
            if (info.WarningType == WarningType.FontSubstitution)
                Console.WriteLine(info.Description);
        }
    }
    
  3. Set the Font Correctly: In your code, you are setting the font for the Korean text. Ensure that you are setting the font name and locale correctly. You might want to set the font for the entire document or ensure that the specific text you are writing has the correct font applied.

  4. Use the Latest Version: Make sure you are using the latest version of Aspose.Words, as updates often include bug fixes and improvements related to font handling and character rendering.

By following these steps, you should be able to resolve the issue with Korean characters not rendering correctly in the PDF output. If the problem persists, consider checking the Aspose documentation or forums for additional support.

Sources:
[1]: Support Korean characters

When I use WarningCallback; I got this error: "
Retry failed after 6 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No connection could be made because the target machine actively refused it"

My main question is : I am deploying my code to cloud using a linux machine, so what should I do to use these fonts in cloud, should I implement it in my solution? In my local machine I have already have the font file for “Malgun Gothic”

@kubra1234 I cannot reproduce the problem on my side using the following simple code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.NameFarEast = "Malgun Gothic";
builder.Font.LocaleIdFarEast = new CultureInfo("ko-KR", false).LCID;

builder.Write("할인소비자가");

doc.Save(@"C:\Temp\out.pdf");

out.pdf (8.6 KB)

The problem with rendering on Linux machine occur because fonts required to render the document are not availabe. The fonts are required to build document layout. If Aspose.Words cannot find the font used in the document, the font is substituted . This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

I could also render the hardcoded part, but my actual file is not being rendered:= >

using var pdfStream = new MemoryStream();
document.Save(pdfStream, SaveFormat.Pdf);

@kubra1234 Could you please provide your input and output documents here for testing? We will test the scenario on our side and provide you more information. Have you tried implementing IWarningCallback as suggested above?

inputFile.docx (12.6 KB)

outputFile.pdf (71.9 KB)

Here is my code

      public async Task<MemoryStream> GenerateDocument(string jsonData)
      {
          var wordService = _documentCreatorFactory.CreateDocumentService(OutputFormatEnum.Word);

          var wordByteStream = await wordService.GenerateDocument(jsonData);

          await ApplyAsposeLicenseAsync();

          var document = new Document(wordByteStream);

          var builder = new DocumentBuilder(document);

          builder.Font.NameFarEast = "SimSun";
          builder.Font.LocaleIdFarEast = new CultureInfo("zh-CN", false).LCID;
          builder.Writeln("你好世界"); // Example Chinese Text

          builder.Font.NameFarEast = "Malgun Gothic";
          builder.Font.LocaleIdFarEast = new CultureInfo("ko-KR", false).LCID;
          builder.Write("할인소비자가"); // Example Korean Text

          using var pdfStream = new MemoryStream();
          document.Save(pdfStream, SaveFormat.Pdf);

          return pdfStream;
      }

In the input file I kept only the first table as an example, I have already tried IWarningCallBack, it did not show anything, I want to again mention that, I need to deploy my code on cloud in a linux machine

@kubra1234 Thank you for additional information. The problem occurs because the available fonts does not have the required glyphs. The problem does not occur if install Batang font:
batang.zip (6.5 MB)

Thanks for the help, now I am able to generate pdf’s in Korean, Japanese and Chinese in my windows local machine, could you please also help me how can I deploy it to as an application running on Azure Cloud which has a Linux operating system?

@kubra1234 To properly render documents the required fonts must be available in the environment where the document is rendered. So you should either install the font in the target environment or provide the fonts using other way, for example using StreamFontSource.