Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non english language characters are not rendered properly in PDF even after loading the necessary fonts. #1100

Closed
techttiru opened this issue Jul 19, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@techttiru
Copy link

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.

Screen Shot 2022-07-19 at 7 33 04 PM

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

Appreciate the response!.
Thanks.

@techttiru techttiru added bug Something isn't working needs triage labels Jul 19, 2022
@aliaafreen
Copy link

I also facing same issue. I am using Hindi and English characters in receipt. I have applied Hind font for Hindi characters but it gives text in non proper format.
Screenshot_2022-07-22-12-27-39-021_cn wps xiaomi abroad lite

@techttiru
Copy link
Author

Here is the work around for tamil font issue.
#198 (comment)

@DavBfr
Copy link
Owner

DavBfr commented Jul 25, 2022

Duplicates #198

@suryaishnavi
Copy link

Same problem with the Telugu font is there any work around?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants