pdfmake install custom fonts on server side for CJK, arabic, and other foreign languages

戏子无情 提交于 2020-01-25 07:32:05

问题


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?


回答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



来源:https://stackoverflow.com/questions/59759483/pdfmake-install-custom-fonts-on-server-side-for-cjk-arabic-and-other-foreign-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!