pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Right to left language (RTL)

Open eladsof opened this issue 10 years ago • 60 comments

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).

eladsof avatar Feb 01 '15 08:02 eladsof

+1

legshooter avatar Jul 14 '16 15:07 legshooter

Requires implementation in the library pdfkit, issue: https://github.com/devongovett/pdfkit/issues/219.

liborm85 avatar Dec 27 '16 12:12 liborm85

+1

dehghani-mehdi avatar Dec 27 '16 14:12 dehghani-mehdi

+1

MohamadKhateeb avatar Aug 07 '17 08:08 MohamadKhateeb

+1

Tonio31 avatar Aug 22 '17 15:08 Tonio31

+1

YousefMMS avatar Aug 27 '17 18:08 YousefMMS

+1

pkhodaveissi avatar Sep 13 '17 09:09 pkhodaveissi

+1

Julian-Sam avatar Sep 16 '17 11:09 Julian-Sam

+1

HabibAllah09 avatar Sep 17 '17 11:09 HabibAllah09

+1

wael-abualhija avatar Sep 17 '17 11:09 wael-abualhija

+1

josephoun avatar Sep 17 '17 11:09 josephoun

+1

Emerald-RD avatar Sep 17 '17 13:09 Emerald-RD

+1

eranpp avatar Sep 17 '17 13:09 eranpp

+1

soroushm avatar Sep 20 '17 18:09 soroushm

Hi, any update on this ?

jihadrhamza avatar Oct 15 '17 08:10 jihadrhamza

Guys we are shifting to latex for Persian https://www.latex-project.org/

Good Luck

soroushm avatar Oct 15 '17 12:10 soroushm

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 avatar Dec 05 '17 13:12 kedrovski

@kedrovski For Farsi is not working because between some world have space

soroushm avatar Dec 07 '17 11:12 soroushm

Could we use some thing like : defaultStyle: { alignment: 'right', direction: 'rtl', }

? 💯

sayjeyhi avatar Dec 14 '17 12:12 sayjeyhi

@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)

sayjeyhi avatar Dec 16 '17 08:12 sayjeyhi

Does it supports "RTL" now?

HussainRauf avatar Dec 26 '17 12:12 HussainRauf

Any updates on this issue?

YogliB avatar Nov 28 '18 07:11 YogliB

When I can get the good news from this feature?

Uysim avatar Jan 01 '19 08:01 Uysim

+1

chaitanyalivehealth avatar Feb 27 '19 06:02 chaitanyalivehealth

Is there any updates ?

motawfik98 avatar Mar 25 '19 13:03 motawfik98

There is no Update On This Issue????

PooriaShariatzadeh avatar Aug 29 '19 14:08 PooriaShariatzadeh

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.

andreialecu avatar Sep 05 '19 09:09 andreialecu

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.

alex-enchi avatar Nov 07 '19 00:11 alex-enchi

+1 Please :)

lesrpo avatar Feb 19 '20 07:02 lesrpo

+1 2020 !!

AmgadTeraNinja avatar Apr 03 '20 02:04 AmgadTeraNinja