我正在使用pdfMake创建PDF。我检查了文本的内容,然后才决定要使用哪种字体,具体取决于除韩语外其他语言是否正常。
使用此字体https://fonts.google.com/specimen/Nanum+Gothic?selection.family=Nanum+Gothic&selection.subset=korean。 我检查了10种以上的韩语字体,所有的字体都缺少字符。 (https://www.google.com/get/noto/#sans-kore或https://fonts.google.com/?subset=korean) vfs_fonts.js.zip
经过大量研究,我喜欢一种能使KaigenSansSC-*。ttf(https://github.com/m13253/kaigen-fonts)正常工作的字体,但它是一种非常笨重的字体(23.MB),喜欢使用较小的字体。
关于如何解决它的任何建议,我将非常感谢。谢谢!
import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "other/vfs_fonts";
pdfMake.fonts = {
"Roboto":{
"bold":"Roboto-Medium.ttf",
"normal":"Roboto-Regular.ttf"},
"NanumGothic":{
"bold": 'NanumGothic-Regular.ttf',
"normal": 'NanumGothic-Regular.ttf'},
"NotoSansEthiopic":{
"normal": 'NotoSansEthiopic-Regular.ttf',
"bold": 'NotoSansEthiopic-Bold.ttf'}
};
function getFont(string) {
if (checkAmharic(string)) {
return "amharic_font";
} else if (checkKorean(string)) {
return "korean_font";
} else {
return "default_font";
}
}
function checkAmharic(x) {
return /[\u1200-\u137F]/.test(x); // will return true if an amharic letter is present
}
function checkKorean(x) {
return /[가-힣]+/.test(x); // will return true if an Korean letter is present
}
var caseDocDefinition = {
content:
[ 'ASCII-1: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z',
'ASCII-2: a b c d e f g h i j k l m n o p q r s t u v w x y z',
'ASCII-3: 0 1 2 3 4 5 6 7 8 9',
'ASCII-4: . , : ; - _ ! ? / " \' ` ^ ~ * + = \\ | # $ @ % & ( ) < > [ ] { }',
'German: Ä Ö Ü ä ö ü ß',
'Czech-1: Á Č Ď É Ě Í Ň Ó Ř Š Ť Ú Ů Ý Ž',
'Czech-2: á č ď é ě í ň ó ř š ť ú ů ý ž',
'Romanian-1: Ă Â Î Ş Ţ',
'Romanian-2: ă â î ş ţ',
'Slovenian-1: Č Š Ž',
'Slovenian-1: č š ž',
'Slowak-1: Á Ä Č Ď É Í Ľ Ĺ Ň Ó Ô Ŕ Š Ť Ú Ý Ž',
'Slowak-2: á ä č ď é í ľ ĺ ň ó ô ŕ š ť ú ý ž',
'Special: § ´ ² ³ ° µ €',
'polish: Cześć',
{width:350, text: '여보세요', style: getFont('여보세요'), alignment: 'justify'},
{width:350, text: 'some other text', style: getFont('some other text'), alignment: 'justify'},
{width:350, text: 'ሰላም', style: getFont('ሰላም'), alignment: 'justify'}
],
defaultStyle: {
font: "Roboto"
},
styles: {
amharic_font: {
font: "NotoSansEthiopic",
margin: [10,0,0,2]
},
korean_font: {
font: "NanumGothic",
margin: [10,0,0,2]
},
default_font: {
font: "Roboto",
margin: [10,0,0,2]
}
}
}
/* Create the pdf */
pdfMake.createPdf(caseDocDefinition).open();