0

I am using PDFMake to generate PDFs on the sever-side with NodeJS 12.

The PDFs are rendering text that has a mix of english and foreign language characters. The PDFs are working, however, none of the foreign language characters are rendering correctly. I did some research and it looks like I need to install a custom font that can handle foreign language characters.

I followed the accepted answer here to install the Google NotoSans font on the server side.

How to create a PDF on Node.js using PDFMake and vfs_fonts?

  fonts = {
    NotoSans: {
      normal: path.join(__dirname, '..', 'public', 'fonts/NotoSans-unhinted/NotoSans-Black.ttf'),
      bold: path.join(__dirname, '..', 'public', 'fonts/NotoSans-unhinted/NotoSans-Bold.ttf'),
      italics: path.join(__dirname, '..', 'public','fonts/NotoSans-unhinted/NotoSans-BlackItalic.ttf'),
      bolditalics: path.join(__dirname, '..', 'public','fonts/NotoSans-unhinted/NotoSans-BoldItalic.ttf'),
    },
  }

The font is installed correctly (all english characters are shown in this font correctly). However, Chinese and other foreign language characters are not working (they are just appearing as as empty rectangles).

What are some other troubleshooting steps I can take to solve this issue? Thank you!

Update: The font I installed doesn't actually support all of the languages I need, is there a font that does support it? Or do I need to find a way to combine multiple fonts into a single font?

pengz
  • 2,279
  • 3
  • 48
  • 91

2 Answers2

1

You have to check the language support of the font!

Noto Sans don't have Chinese neither Arabic support. DOCS

You can detect the language of the content and redirect to the right font: Noto Fonts List or use a font with a wide language support, like Unicode Fonts

  • Thanks, I just noticed that. So do I need to find a single font that has all of the languages supported? Or can I install multiple fonts to take care of this? Noto does have a CJK variant as well as Arabic. – pengz Jan 15 '20 at 21:10
  • 1
    You can detect the language of the content and redirect to the right font, that is another question. –  Jan 15 '20 at 21:14
  • 1
    The content is mixed, though, so not sure if detection will work. There are lines of text that contain both english language characters and foreign language characters, such as 支那最新大地圖 (Map of China) – pengz Jan 15 '20 at 21:21
  • Awesome, where can I download the Arial Unicode font? – pengz Jan 15 '20 at 21:28
  • 1
    Arial Unicode MS is already installed in Windows, in Linux I don't know –  Jan 15 '20 at 21:32
  • 1
    Take a look again =) –  Jan 15 '20 at 21:38
0

If you use the Arial Unicode MS as @gmazoni segust, you will get all the languages characters simultaneously. Use the process from pdfmake docs and you can download the font from here