pdfmake在服务器端为CJK,阿拉伯语和其他外语安装自定义字体 [英] pdfmake install custom fonts on server side for CJK, arabic, and other foreign languages

查看:157
本文介绍了pdfmake在服务器端为CJK,阿拉伯语和其他外语安装自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PDFMake在NodeJS 12的服务器端生成PDF.

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

PDF正在渲染包含英语和外语字符的文本. PDF可以正常工作,但是,所有外语字符都无法正确呈现.我做了一些研究,看来我需要安装可以处理外语字符的自定义字体.

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.

我按照此处接受的答案在服务器端安装了Google NotoSans字体.

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

如何创建使用PDFMake和vfs_fonts在Node.js上创建PDF?

  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?

推荐答案

您必须检查字体的语言支持!

You have to check the language support of the font!

诺托·桑斯(Noto Sans)没有中文,也没有阿拉伯语支持. DOCS

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

您可以检测内容的语言并重定向到正确的字体: Noto字体列表或使用具有广泛语言支持的字体,例如 Unicode字体

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

这篇关于pdfmake在服务器端为CJK,阿拉伯语和其他外语安装自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆