问题
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