I am using PDF package in flutter web. Everything is good but when i try to use non-english language, its not showing the character properly. for example (Tamil + english) , Tamil is a language and when i use the character from this language its not showing the character properly.

I did research multiple issues that are related to similar problem and i did load the necessary font in application but characters are not showing correctly.

here is the code.

Future<Uint8List> createSecondPdf(
    List<AttendeeListViewModel> attendeeListViewModelList) async {
  var mytheme = ThemeData.withFont(
    base: Font.ttf(await rootBundle.load("assets/HindMadurai-Regular.ttf")),
    bold: Font.ttf(await rootBundle.load("assets/HindMadurai-Regular.ttf")),
    italic: Font.ttf(await rootBundle.load("assets/HindMadurai-Regular.ttf")),
    boldItalic:
        Font.ttf(await rootBundle.load("assets/HindMadurai-Regular.ttf")),
  );
  // final pdf = Document(theme: mytheme);
  final pdf = Document();
  //final f1 = await PdfGoogleFonts.hindGunturRegular();
  // final f2 = await rootBundle.load("assets/TAU-Marutham_Bold.ttf");
  print(
      '   ${attendeeListViewModelList[2].attendeeDataModel?.pNameAndProfession ?? ''}');

  final data = await rootBundle.load('assets/HindMadurai-Regular.ttf');
  final loadedfont = Font.ttf(data);

  pdf.addPage(
    MultiPage(
      // theme: mytheme,
      build: ((context) {
        return [
          Table.fromTextArray(
            headers: ['Sl.No', 'Name', 'Data'],
            cellAlignments: {0: Alignment.center},
            cellStyle: TextStyle(font: loadedfont),
            columnWidths: {
              0: const FlexColumnWidth(0.6),
              1: const FlexColumnWidth(4.0),
              2: const FlexColumnWidth(2.0),
            },
            data: <List<String>>[
              <String>[
                'Hello',
                attendeeListViewModelList[2]
                        .attendeeDataModel
                        ?.pNameAndProfession ??
                    '',
                'ஜெயப்பாண்டி'
              ]
            ],
          ),
        ];
      }),
    ),
  );

  return pdf.save();
}

tried multiple options but no luck so far. Any help is really appreciated. Below screen shot show the characters in different way than what i have given in the code.

enter image description here

The below are packages that i am using. pdf: ^3.8.1 printing: ^5.9.1

Appreciate the response!. Thanks.

0

There are 0 best solutions below