pdfmake
pdfmake copied to clipboard
Right to left language (RTL)
Hi,
Is there support for right to left language? I was able to change the font but the letter are written in the wrong order (LTR).
+1
Requires implementation in the library pdfkit, issue: https://github.com/devongovett/pdfkit/issues/219.
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
Hi, any update on this ?
Guys we are shifting to latex for Persian https://www.latex-project.org/
Good Luck
Hi,
For RTL support you can try to use this code:
var inputString = 'שלום עולם'; //Hello World
inputString = inputString.split(" ").reverse().join(" "); //Str to Arr->Reverse array->toString
var data = { content: [ {text: inputString, alignment: 'right'} ] };
pdfMake.createPdf(data).open();
Please note: inside join( ) you should have 2 spaces " " Tested for hebrew, I assume it should work for other RTL languages.
P.S don't forget to include fonts for your language https://github.com/bpampuch/pdfmake/wiki/Custom-Fonts---client-side
@kedrovski For Farsi is not working because between some world have space
Could we use some thing like :
defaultStyle: { alignment: 'right', direction: 'rtl', }
? 💯
@liborm85 I find a way to display correct our string in RTL format. I use this :
var inputString = 'سلام دوستان';
inputString = inputString.replace(" " , " "); //replace space with nbspace char
var data = { content: [ {text: inputString, alignment: 'right'} ] };
pdfMake.createPdf(data).open();
but it has bug with wraping
, in tables if I use this function with a large text the table width will be in one big row .
Can we supply nbspace
(alt255) char instead of space to wrap text ? (I mean edit this source https://github.com/bpampuch/pdfmake/blob/master/src/textTools.js)
Does it supports "RTL" now?
Any updates on this issue?
When I can get the good news from this feature?
+1
Is there any updates ?
There is no Update On This Issue????
I was able to manually handle Hebrew with code like:
npm install twitter_cldr
import * as TwitterCldrLoader from "twitter_cldr";
const TwitterCldr = TwitterCldrLoader.load("en");
class ... {
private isHebrew(text: string) {
var position = text.search(/[\u0590-\u05FF]/);
return position >= 0;
}
private maybeRtlize(text: string) {
if (this.isHebrew(text)) {
var bidiText = TwitterCldr.Bidi.from_string(text, { direction: "RTL" });
bidiText.reorder_visually();
return bidiText.toString();
} else {
return text;
}
}
}
Just pass all text that may be in Hebrew through the maybeRtlize
function.
It's not perfect and I only tested it for Hebrew, but it seems to work pretty good. If you also need right alignment, use something like isHebrew(myText) ? { align: "right" } : null
for alignment.
Is there any way to pass array of words and tell write from right point or from left point? It is possible to use 3rd party libraries and custom solutions to get array of characters, words etc but I can't find a way to pass this data properly to the library.
Small update: if you need a fast solution right now my suggestion is to use this php library https://tcpdf.org/ and create a small micro service for this. Currently I wasn't able to find any js based pdf library that can properly handle rtl languages.
+1 Please :)
+1 2020 !!