How to add Arabic chars in flutter pdf generating How to add Arabic chars in flutter pdf generating dart dart

How to add Arabic chars in flutter pdf generating


just add textDirection: pw.TextDirection.rtl to the Text widget , like this :

 pw.Page(      build: (pw.Context context) => pw.Center(        child: pw.Text(test, style: pw.TextStyle(fontSize: 80,font: myFont),textDirection:         pw.TextDirection.rtl),      ),    ),

Note: Problems may occur if the text contains some numbers


if all your widget has rtl parent all widget with pw.Directionality and set TextDirection.rtl , or use TextDirection.rtl in single text widget


just add theme: ThemeData.withFont(base: ttf,) to the Page widget, like this:

  var data = await rootBundle.load("fonts/IRANSansWeb(FaNum)_Bold.ttf");  final ttf = Font.ttf(data); Page(      pageFormat: PdfPageFormat.a4,      theme: ThemeData.withFont(        base: ttf,      ),      orientation: PageOrientation.landscape,      build: (Context context) {return Align(  alignment: Alignment.center,  child: new Column(      mainAxisAlignment: MainAxisAlignment.spaceBetween,      crossAxisAlignment: CrossAxisAlignment.center,      children: [        Column(          children: [            Row(              children: [                Text(                  'خلیج فارس',                 textDirection: TextDirection.rtl,                )              ]            )          ]        ),        Column(          children: [            Image(compareChartImage),          ]        ),        Column(          children:[            Image(timingChartImage),          ]        )      ]  )); })