How to display Hebrew text in pdf from my custom widget, using jsPDF library

12708
12
Jump to solution
12-23-2020 12:32 AM
MichaelLev
Occasional Contributor III

I'm developing custom widgets for WAB (Develper Edtion) 2.17, Launchpad Theme, on 3D Scenes (ArcGIS API for javascript 4.17), on our compamy portal (version 10.7.1).

I am still a newbie...

I need, from within javascript code of a custom widget, to create pdf file which will contain Hebrew text. I found jsPDF library, incorporated it by its jspdf.umd.min.js file and it creates pdf all right, but I have not succeeded to show Hebrew fonts.

jsPDF is good by the capability to show tables, so I wish to use it right. Maybe I have not set up all things as should be?

Does anyone have some sample code that can output Hebrew text (or Arabic, for example) to pdf, using jsPDF library?

Sample using other library like pdfmake will also help.

Help will be greatly appreciated,

Michael

1 Solution

Accepted Solutions
MichaelLev
Occasional Contributor III
At last I succeeded!
I used the fontconverter as recommended in jsPDF doc  to create js file that I activated and this has not worked for me, but using their 2nd way - downloading the binary ttf file that is also generated by that tool and using it as in thedropdown arabic example in jsPDF site, works well. Actually the ttf file coul be downloaded from other sites also.
I am very happy with jsPDF!

View solution in original post

12 Replies
MichaelLev
Occasional Contributor III
At last I succeeded!
I used the fontconverter as recommended in jsPDF doc  to create js file that I activated and this has not worked for me, but using their 2nd way - downloading the binary ttf file that is also generated by that tool and using it as in thedropdown arabic example in jsPDF site, works well. Actually the ttf file coul be downloaded from other sites also.
I am very happy with jsPDF!
AlaaYahia
New Contributor II

Hey, 

can you show me please how you made it in Hebrew?
I tried this:

 

const doc = new jsPDF();
var font = 'undefined';
var callAddFont = function () {
this.addFileToVFS('Rubik-normal.ttf', font);
this.addFont('Rubik-normal.ttf', 'Rubik', 'normal');
};
jsPDF.API.events.push(['addFonts', callAddFont])
doc.setFont("Rubik-normal"); // set font

but did not work and I still get garbage,

Thank you

0 Kudos
MichaelLev
Occasional Contributor III

I created 2 files, david--normal.js and davidbd-bold.js

each contains:

define([

"https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"

], function (jsPDF) {
var theClass = {
addFont: function (doc) {
var font = '<here comes a very long string of the fone>';

var callAddFont = function () {
doc.addFileToVFS('David-normal.ttf', font);
doc.addFont('David-normal.ttf', 'David', 'normal');
};
jsPDF.jsPDF.API.events.push(['addFonts', callAddFont]);
}

// eof public property functions
};
return theClass;
});

 

Rivki1010
New Contributor

can you pls -add the full code-

10x

0 Kudos
tehilashtechen
New Contributor

Hi 

I followed your instructions
And it works
But - the letters are reversed
For example: I'm trying to print "שלום", prints - םולש
I'm desperate, can you help me?

thank you!

0 Kudos
AlaaYahia
New Contributor II

@MichaelLev  ...

0 Kudos
AlaaYahia
New Contributor II

Thank you! that was really helpful!!!

0 Kudos
KaramShabita
New Contributor II

Hi @MichaelLev  and @AlaaYahia ,

 

can anybody please help me with this.

I downloaded font.ttf and add the following code:

KaramShabita_3-1625393820604.png

 

 

 the output still doesn't include Hebrew characters, I tried also different fonts but still same:

KaramShabita_1-1625393471108.png

 

 

0 Kudos
MichaelLev
Occasional Contributor III

I suggest you do exactly as I explained.

0 Kudos