jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Greek custom fonts, not supported in new version.

Open zeligmanos opened this issue 7 years ago • 10 comments

I'm using the latest version of jsPDF and have managed to successfully implement custom fonts for almost any language (Cyrillic, Japanese etc)! But no matter what I have tried, Greek fonts are never correctly reproduced to .pdf. I encode them to Base64 using your converter and use this code:

var doc = new jsPDF();
doc.addFileToVFS("Arialbd.ttf", font);
doc.addFont("Arialbd.ttf", "arialbd", "bold");
doc.setFont('arialbd');
doc.text(50,50,'Καλημέρα');```

But instead of 'Καλημέρα' I see some bizarre characters being produced. And this happens with all the Greek fonts I have tried. Any idea why this happens with Greek characters? Is it a bug?

zeligmanos avatar Dec 21 '18 15:12 zeligmanos

Can you provide the testcase in a zip-file?

Uzlopak avatar Dec 21 '18 15:12 Uzlopak

Thanks for the prompt reply. I'm attaching a test case zip file including the original font I used to encode to base64 (I can also send you more fonts to try but it's the same with every font I tried - no Greek characters are displayed) GreekCharacters.zip Any insight on what might be causing this issue would be greatly appreciated.

zeligmanos avatar Dec 21 '18 15:12 zeligmanos

verified as a bug.

Uzlopak avatar Dec 21 '18 15:12 Uzlopak

If you do setFont("Arialbd") it would work. there is a problem with case sensitivity

Uzlopak avatar Dec 22 '18 04:12 Uzlopak

After several more tests with other fonts, I realized that the issue described above occured in certain fonts only. Upon testing it with a font that is free to use (Arial Unicode) -despite its big size (a little more than 20mb)- I can verify that it covers the vast majority of languages (including cyrillic, Greek, Asian etc). So by encoding that font to Base64 I'm now able to display Greek properly through jsPDF.

And yes, you are right about the case sensitivity, cause even the Arial Unicode font does not work if I use different letter capitalization.

zeligmanos avatar Dec 22 '18 07:12 zeligmanos

i reopen this issue, because it is still a bugreport

Uzlopak avatar Dec 22 '18 14:12 Uzlopak

Indeed, sorry for rushing to close it.

zeligmanos avatar Dec 22 '18 22:12 zeligmanos

It is not a bug. I realized, that your code is faulty.


		var greek_text = $('#greektext').val();
		var doc = new jsPDF();
		doc.addFileToVFS("Arialbd.ttf", font);
		doc.addFont("Arialbd.ttf", "arialbd", "bold");
		doc.setFont('arialbd', 'bold');

you should have selected the font as bold. You did not, so jsPDF couldnt find the font. If you modify your code accordingly your font will work.

No Bug.

Uzlopak avatar Dec 24 '18 22:12 Uzlopak

Unfortunately, it does not work if I set the font in "bold". If you notice my initial thread post, I had set the font as bold. Even after using correct capitalization and setting it to bold it reproduces the characters incorrectly. I just tried it. I'm reattaching a test case including the original font that was converted to Base64, so that you verify this. So it is still a bug. GreekFontsApp.zip

zeligmanos avatar Dec 27 '18 14:12 zeligmanos

It works as expected if you use the latest jspdf (1.5.3) and set the font to bold ( doc.setFont('Arialbd', 'bold'); )

index.zip

Uzlopak avatar Dec 27 '18 17:12 Uzlopak