Search code examples
unicodepdfkitpdfmake

Is there anyway to bypass this error on pdfmake? "Type Error: Cannot read property 'syllable' of null"


I'm using pdfmake to generate PDF with Sinhala unicode characters using "Iskoola Pota" font. Most of the unicode characters work perfectly. But when the document contains certain characters such as \u0dda, and \u0ddd, it throws this error from fontkit module.

"Type Error: Cannot read property 'syllable' of null"

(It doesn't throw an error when I use the other common fonts. But I have to use "Iskoola Pota" since I want to display the characters correctly.)

Issue: https://github.com/bpampuch/pdfmake/issues/1916


Solution

  • I had the same problem with both PDFmake & PDFkit. I found a solution yesterday and this may help those who are having the same issue.

    I am using PDFmake version 0.1.65. In your installed directory there is a sub-directory named ./node_modules/fontkit. Go to that directory and you will find a file called index.js. Open index.js in a text editor and search the word 'Sinhala', or you may go to line 9601 (hopefully you will find the same if it is version 0.1.65). Whichever way you should get to the line "sinh: UniversalShaper" inside function nextSyllable$1() like below.

    function nextSyllable$1(glyphs, start) {
            :
    sinh: UniversalShaper, // Sinhala
            :
    }
    

    Now, change UniversalShaper to IndicShaper and save and exit the file.

    I have not done extensive testing on this but satisfied it doing what I intend to do. Hopefully, this will help you too. I also will report this to Bartek Pampuch (PDFmake author) to have a look.