pdfMake / pdfKit Отсутствуют корейские символы - отображается пустым - PullRequest
0 голосов
/ 30 января 2019

Я использую 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();
...