bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.7k stars 2.04k forks source link

Korean characters missing #1614

Closed Avital-Kapiloff closed 5 years ago

Avital-Kapiloff commented 5 years ago

Hi, I'm creating a PDF and I need support for Korean, Amharic, Polish, English. I can't find one font that contains them all. I don't know the content of the text so I can't specify what font to use. How do I overcome that issue? Thanks.

example of content that should work...

var dd = {
    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ść',
        'Amharic: ሰላም',
        'Korean: 여보세요'
]}
malloc32 commented 5 years ago

Same problem, but other languages. CJK, arabian,.... At the moment mixing ttf fonts with FontForge, not sure if all characters are working.

Thank you.

liborm85 commented 5 years ago

If you did not find one font file with all the necessary character sets. Of if not you must use different fonts for different character sets, example:

var dd = {
    content: [
        {text: 'Text A', font: 'Roboto'},
        {text: 'Text B', font: 'Otherfont1'},
        {text: 'Text C', font: 'Otherfont2'},
    ]
};
malloc32 commented 5 years ago

But the problem is that I don't know when I have to use Roboto or when I have to use Othefont because I don't know the language of the text.

liborm85 commented 5 years ago

Then is required font file with all necessary character sets.

Avital-Kapiloff commented 5 years ago

@liborm85 Thank you for your response!

I decided to check the content of the text and only then decide what font to use depending on the language it's working fine except the Korean. is there different behaver for Korean letters?

using this font https://fonts.google.com/specimen/Nanum+Gothic?selection.family=Nanum+Gothic&selection.subset=korean - i tried a few diffaret fonts it still didn't work for me (https://www.google.com/get/noto/#sans-kore)

vfs_fonts.js.zip

any clue what is going on? I'm getting an empty space where the Korean text should go

screen shot 2019-01-28 at 11 22 19 am

Thanks!

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();
liborm85 commented 5 years ago

Probably font NanumGothic not support this characters and therefore blank space is displayed.

Avital-Kapiloff commented 5 years ago

I tried a bunch of other korean fonts it didn't work for me

Avital-Kapiloff commented 5 years ago

I was wondering if it could be the way the font is built that the library cant read it? I think I'm having the same issue as this https://github.com/bpampuch/pdfmake/issues/1168

malloc32 commented 5 years ago

Same problem with korean (this is the output, japanese, arabian, chinese, greek an. korean) have a problem with one chinese character. \u{304b}\u{304d}\u{306f}\u{304f}\u{307e} لبرانننلببهعغفف 不是杂志。那是字典 ηγωσσερθ 호ㅓㅑㅐㅛㅅㄱThis is a sta image

Avital-Kapiloff commented 5 years ago

I used the exact font that he mentions in this comment to solve the issue other fonts didn't work for me. https://github.com/bpampuch/pdfmake/issues/1168#issuecomment-342418274

liborm85 commented 5 years ago

Pdfmake using pdfkit library for rendering PDF files, please create issue there. Thanks.

liborm85 commented 5 years ago

Released in 0.1.54.

Avital-Kapiloff commented 5 years ago

working great! thank you!

virajshirshikar commented 3 years ago

Hello all, I am trying to download the pdf for korean and chinese character. I read this blog and working great for korean but for chinese, some character are missing.