Search code examples
flutterdartpdfmultilingual

Gujrati font Rendering problem in Flutter PDF


I am Developing a Mobile application using Flutter 2.0, this whole application is in the Gujarati language, the application is ready, all text is rendering perfectly in the app, but when I generate pdf from data that are on the screen, the Gujarati fonts not rendering correctly,

I am using plugin

pdf: ^3.0.1

for Ex,

there is the string on-screen is લોગિન and when I print in pdf it becomes લોગનિ

Same for another ઉત્સવ becomes ઉત્ સવ(ignore space between words)


Solution

  • Use this flutter library

    https://pub.dev/packages/syncfusion_flutter_pdf#create-a-pdf-document-from-simple-text

    //Create a new PDF document.
    final PdfDocument document = PdfDocument();
    //Read font data.
    final Uint8List fontData = File('arial.ttf').readAsBytesSync();
    //Create a PDF true type font object.
    final PdfFont font = PdfTrueTypeFont(fontData, 12);
    //Draw text using ttf font.
    document.pages.add().graphics.drawString('Hello World!!!', font,
        bounds: const Rect.fromLTWH(0, 0, 200, 50));
    // Save the document.
    File('TrueType.pdf').writeAsBytes(document.save());
    // Dispose the document.
    document.dispose();