Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No unicode cmap for font" happened when i using client version. #290

Closed
darkautism opened this issue May 15, 2015 · 26 comments
Closed

"No unicode cmap for font" happened when i using client version. #290

darkautism opened this issue May 15, 2015 · 26 comments
Labels

Comments

@darkautism
Copy link

I use chinese fonts in my project.
When i using server version, it work perfectly.
But when i using client version, it always alert me "No unicode cmap for font".
This is font i used :
https://mega.co.nz/#!WddCwIjR!XVwz3BH8brUc0znBSNQ_vb_NG9iHXtW0ghlkEWz9lo8
This is vfs_fonts.js i builed :
https://mega.co.nz/#!DN9DmSYD!Nd10rPBBfTZ9OFpw7MEQm5A_wrqcQhpECH0z3RLHy-k
This is code i used :

        var fontDescriptors = { 
            times: {
                normal: 'times.ttf',
                bold: 'timesbd.ttf',
                italics: 'timesi.ttf',
                bolditalics: 'timesbi.ttf'
            } , 
            wqy: {
                normal: 'wqy.ttf',
                bold: 'wqy.ttf',
                italics: 'wqy.ttf',
                bolditalics: 'wqy.ttf'
            }

        };
        pdfMake.fonts = fontDescriptors;
        var docDefinition = { content: 'wqy中文wqy',
        defaultStyle: {
            font: 'wqy'
        }};

               pdfMake.createPdf(docDefinition).open('test.pdf');

G3548817

@jthoenes jthoenes added bug and removed bug labels May 18, 2015
@jthoenes
Copy link
Contributor

Your font needs to have a Unicode CMAP - can you verify that is has one?

See foliojs/pdfkit#121 (comment)

@darkautism
Copy link
Author

If this font do not have a Unicode CMAP, why can this run in server mode perfectly?

@jthoenes
Copy link
Contributor

I don't know your setup, so I cannot answer the question.

Assuming the CMap is present in the vfs_fonts, there might be space issue inside your browsers. Have you checked (with Chrome debugger) if it gets loaded correctly?

@darkautism
Copy link
Author

This is server version:
http://i.imgur.com/BTJWzTv.png

It work correctly.

Because this font work correctly so i assume this font have a Unicode CMAP, but it cannot work on client version.

This is client version:
http://i.imgur.com/cVZpMRm.png

Uncaught Error: No unicode cmap for font

pdfmake.js:22153 Uncaught Error: No unicode cmap for fontPDFFont.registerTTF @ pdfmake.js:22153PDFFont @ pdfmake.js:22026module.exports.font @ pdfmake.js:19762FontWrapper.getFont @ pdfmake.js:14190FontWrapper.widthOfString @ pdfmake.js:14201(anonymous function) @ pdfmake.js:16133measure @ pdfmake.js:16118TextTools.buildInlines @ pdfmake.js:15941DocMeasure.measureLeaf @ pdfmake.js:14557(anonymous function) @ pdfmake.js:14437StyleContextStack.auto @ pdfmake.js:16306DocMeasure.measureNode @ pdfmake.js:14422DocMeasure.measureDocument @ pdfmake.js:14409LayoutBuilder.tryLayoutDocument @ pdfmake.js:2425LayoutBuilder.layoutDocument @ pdfmake.js:2413PdfPrinter.createPdfKitDocument @ pdfmake.js:285Document._createDoc @ pdfmake.js:81Document.getDataUrl @ pdfmake.js:160Document.open @ pdfmake.js:108onclick @ Test.html:32

@jthoenes
Copy link
Contributor

Your font (one of the two) does not have a unicode cmap when it gets loaded by pdfkit - the underlying pdf engine of pdfmake.

I cannot tell why this is the case - and I don't have time to look deeper into it myself at the moment.

If you want to investigate yourself, try to use the Chrome debugger to see, what is going wrong. This might or might not be a pdfkit bug, rather than a pdfmake bug.

@hillelcoren
Copy link

+1

I believe I'm running into the same problem. I'm using the Google Noto CJK font (https://www.google.com/get/noto/#/) and I'm seeing the same error.

@darkautism
Copy link
Author

I solved this problem.
I remove other english font (e.g. Times New Roman) and only use one Unicode CMAP fonts.
It's work.
So all of the fonts should have Unicode CMAP in client version, but sever version shouldn't.

@hillelcoren
Copy link

@darkautism

Can you share the updated vfs_fonts.js file you're using?

Thanks

@darkautism
Copy link
Author

https://mega.co.nz/#!zdVH3bSJ!6lN1vO5_Ty0i0rOljyJrZMConTklVjDiL_Egw6vps5I
This file only have wqy.ttf

var fontDescriptors = {
wqy: {
normal: 'wqy.ttf',
bold: 'wqy.ttf',
italics: 'wqy.ttf',
bolditalics: 'wqy.ttf'
}
};
pdfMake.fonts = fontDescriptors;
var docDefinition = { content: 'wqy中文wqy',
defaultStyle: {
font: 'wqy'
}};

@hillelcoren
Copy link

Amazing, thanks!

@jthoenes jthoenes closed this as completed Jun 9, 2015
@hillelcoren
Copy link

@darkautism

I haven't been able to get it to work. Any chance you could put together a mini-sample project of Chinese working. It'd be a great help.

@Joeper214
Copy link

+1
I also tried the above codes. But it seems not to be working for me. Any workaround on this guys?

@hillelcoren
Copy link

We were able to get Chinese working in our project: https://github.com/invoiceninja/invoiceninja

It took us a while to find an open-source font which worked, we ended up using Ukai:

http://www.freedesktop.org/wiki/Software/CJKUnifonts/Download/

@Joeper214
Copy link

@hillelcoren

Thanks for the information. But I got confused on the implementation on your project. is it the ukai.js file needed for the font mapping or there are a bunch of ways?

@hillelcoren
Copy link

Yes, that's the correct font file.

@Joeper214
Copy link

Thanks A lot. I got it working now. @hillelcoren

@outprog
Copy link

outprog commented Apr 5, 2016

@hillelcoren @Joeper214 i download ttc file, Uncaught Error: Font ukai(normal)0 not found in TTC file. how u woking?

@hillelcoren
Copy link

@outprog
Copy link

outprog commented Apr 6, 2016

@hillelcoren i download this file and use this config:

                var fontDescriptors = {
                ukai: {
                    normal: 'UKai.ttf',
                    bold: 'UKai.ttf',
                    italics: 'UKai.ttf',
                    bolditalics: 'UKai.ttf'
                }
            };
            pdfMake.fonts = fontDescriptors;
            var docDefinition = { content: 'wqy中文wqy',
                defaultStyle: {
                    font: 'ukai'
                }
            };
            pdfMake.createPdf(docDefinition).open('test.pdf');

but not working. console log is 'Uncaught TypeError: Cannot read property 'UKai.ttf' of undefined'

@Joeper214
Copy link

I think Ukai.ttf is also not working on me. I tried another way and wrote this blog.

Please check it out: http://www.skyarch.net/blog/?p=5673

@askie
Copy link

askie commented May 25, 2016

@hillelcoren
pdfmake.js:21668 Uncaught TypeError: Cannot read property 'UKai.ttf' of undefined

@hillelcoren
Copy link

@askie did you mean to create the issue with this project or our app?

@88kbbq
Copy link

88kbbq commented Nov 6, 2019

We were able to get Chinese working in our project: https://github.com/invoiceninja/invoiceninja

It took us a while to find an open-source font which worked, we ended up using Ukai:

http://www.freedesktop.org/wiki/Software/CJKUnifonts/Download/

I just installed the NotoSansCJKtc-Light font successfully, but Chinese appears normal while English in this font is spaced one letter per line, vertically, and the document is dozens of pages. Why did you choose Ukai and are there any other Chinese fonts that will display both Chinese and English properly?

@hillelcoren
Copy link

We chose Ukai because it worked and was open source. This was a few years ago, it's certainly possible there are better fonts to use.

@blikblum
Copy link
Contributor

A bug with NotoSansCJK fonts where fixed in foliojs/fontkit#207 but not released yet. In the mean time you can try https://www.npmjs.com/package/pdfkit-next

@88kbbq
Copy link

88kbbq commented Nov 14, 2019

Too bad the NotoSansCJK fix hasn’t been released yet. Great clear font for Chinese, but without English it won’t work. I used Transtype 4 to export local Chinese fonts .ttf and they all work in Invoice Ninja. Loving my PDF invoices now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants