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

PDF creation fails with custom fonts using new version of pdfmake #821

Closed
sklinga opened this issue Jan 9, 2017 · 9 comments
Closed

PDF creation fails with custom fonts using new version of pdfmake #821

sklinga opened this issue Jan 9, 2017 · 9 comments

Comments

@sklinga
Copy link

sklinga commented Jan 9, 2017

We have a working code base to create PDF using custom fonts(Univers) with pdfmake-0.1.17.
We want to use pdfmake-0.1.23 or later for the custom links fix but we are seeing the below error with the custom fonts, is there anything changed with fonts in latest release?

TypeError: Cannot read property 'records' of undefined
at TTFFont.get (pdfmake.js:50606:28)
at new EmbeddedFont (pdfmake.js:70666:29)
at Function.PDFFont.open (pdfmake.js:37654:15)
at PDFDocument.font (pdfmake.js:37593:29)
at FontProvider.provideFont (pdfmake.js:19881:56)
at pdfmake.js:21351:28
at Array.forEach (native)
at measure (pdfmake.js:21338:14)
at TextTools.buildInlines (pdfmake.js:21145:18)
at DocMeasure.measureLeaf (pdfmake.js:20768:29)

Appreciate any help with this issue.

Regards,
Sunil

@sklinga sklinga changed the title PDF creation fails with custom fonts using new verion of pdfmake PDF creation fails with custom fonts using new version of pdfmake Jan 9, 2017
@devongovett
Copy link
Contributor

@sklinga sounds like maybe the font has no name table. can you please send the file to me? [email protected]

@sklinga
Copy link
Author

sklinga commented Jan 9, 2017

@devongovett I can not share Univers font file due to licensing restrictions, but, I tried with the below font and I got the same issue
http://www.webpagepublicity.com/free-fonts/x/Xeranthemum.ttf

Thanks again for you help!

@sklinga
Copy link
Author

sklinga commented Jan 9, 2017

On further debugging, looks like it is failing decoding the name table. I see below error

Uncaught Error: Encoding '_sbcs' has incorrect 'chars' (must be of len 128 or 256)(…)
SBCSCodec @ pdfmake.js:52920
getCodec @ pdfmake.js:52096
getDecoder @ pdfmake.js:52118
decode @ pdfmake.js:52036
DecodeStream.readString @ pdfmake.js:51961

Strangely, when I run the code to create PDF with the same custom fonts as standalone outside our big app code base, it works fine.
The problem seems to be only when running the PDF creation within the entire app code base. Not sure if some thing else we have in our app code may have been causing the font decoding failed with recent pdfmake release!!?

Any help/pointers on this issue is greatly appreciated!

@liborm85
Copy link
Collaborator

Pdfmake v0.1.24 using the newer fontkit library, that are probably some bugs. :(
foliojs/fontkit#65
#818

We must wait until it fix @devongovett.

@liborm85
Copy link
Collaborator

@devongovett Please also see this bug #818

@liborm85
Copy link
Collaborator

@sklinga The same or similar error is in issue #828. Do you have <meta charset="utf-8"> in the <header>?

@liborm85
Copy link
Collaborator

No reaction.

@tdolphin
Copy link

I had exactly the same problem (old version <0.1.20 works but not new one) and adding
<meta charset="utf-8">
to the header solved it.

@sklinga
Copy link
Author

sklinga commented Mar 6, 2017

Sorry for the very long delay in responding. We had to put this upgrade aside for sometime.

Adding meta tag to the header did not solve the issue in my case. I had to add the charset attribute to the script tag that is loading the pdfmake.js

<script type="text/javascript" src="/js/dependencies.js" charset="utf-8"></script>

pdfmake.js and few other libraries are concatenated in to dependencies.js file.

Thanks everyone for the inputs, I appreciate the help.

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

No branches or pull requests

4 participants