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

Emoji's not displaying in PDF generated with dart_pdf #1652

Open
MarkOSullivan94 opened this issue Apr 22, 2024 · 2 comments
Open

Emoji's not displaying in PDF generated with dart_pdf #1652

MarkOSullivan94 opened this issue Apr 22, 2024 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@MarkOSullivan94
Copy link

MarkOSullivan94 commented Apr 22, 2024

Describe the bug

Whenever trying to write a table with emoji's included in the header it doesn't print the emojis.

To Reproduce
Code snippet to reproduce the behavior:

import 'dart:io';

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;

Future<void> main(List<String> arguments) async {
  await buildPdf();
}

Future<void> buildPdf() async {
  final document = pw.Document(pageMode: PdfPageMode.outlines);
  final defaultFont = pw.Font.helvetica();
  final boldFont = pw.Font.helveticaBold();

  document.addPage(
    pw.Page(
      theme: pw.ThemeData.withFont(
        base: defaultFont,
        bold: boldFont,
      ),
      build: (pw.Context context) {
        return pw.TableHelper.fromTextArray(
          context: context,
          border: pw.TableBorder.all(width: 0.2),
          data: <List<String>>[
            ['', '✅ Passed', '❌ Failed'],
            ['my_app', '0', '100'],
            ['my_package', '20', '0']
          ],
          cellAlignments: {
            0: pw.Alignment.topCenter,
            1: pw.Alignment.topCenter,
            2: pw.Alignment.topCenter
          },
        );
      },
    ),
  );

  final file = await File('output/report.pdf').create(recursive: true);
  await file.writeAsBytes(await document.save());
}

Expected behavior

After creating the PDF document with dart_pdf I would see emoji's in the document

Screenshots

This is what the produced PDF shows

Screenshot 2024-04-22 at 14 51 45

Additional context

This is a command-line app so I am unable to make use of any Flutter packages

dart_pdf: ^3.10.8

Dart SDK version: 3.1.5 (stable) (Tue Oct 24 04:57:17 2023 +0000) on "macos_arm64"

@MarkOSullivan94 MarkOSullivan94 added bug Something isn't working needs triage labels Apr 22, 2024
@DavBfr
Copy link
Owner

DavBfr commented Apr 24, 2024

You need to load an emoji font.
Look at https://github.com/DavBfr/dart_pdf/blob/master/pdf/test/widget_text_test.dart#L362

@MarkOSullivan94
Copy link
Author

You need to load an emoji font. Look at https://github.com/DavBfr/dart_pdf/blob/master/pdf/test/widget_text_test.dart#L362

I've tried that already with Noto Color Emoji font but it didn't work. What font do you recommend?

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

No branches or pull requests

2 participants