'create icons in flutter pdf?
I need a add icons in flutter pdf. This was completely different when compared with add icons in flutter. I am using https://pub.dev/packages/pdf this package.
Here is the code :
pw.Icon(pw.IconData(0xe047));
Error was :
ArgumentError (Invalid argument (string): Contains invalid characters.: "")
Solution 1:[1]
check whether PdfGoogleFonts.materialIcons() is added under page theme:
theme: pw.ThemeData.withFont(
base: await PdfGoogleFonts.openSansRegular(),
bold: await PdfGoogleFonts.openSansBold(),
icons: await PdfGoogleFonts.materialIcons(), // this line
)
Solution 2:[2]
Set your custom icons using www.fluttericon.com
using pw.ThemeData.withFont like this
var pathToFile = await rootBundle.load('- your icon font file (.ttf) -');
final ttf = pw.Font.ttf(pathToFile);
// load ttf to pdf theme
final theme = pw.ThemeData.withFont(
base: await PdfGoogleFonts.robotoCondensedRegular(),
bold: await PdfGoogleFonts.robotoCondensedBold(),
icons: ttf,
);
final pw.Icon(pw.IconData(customIcon.icon.codePoint), size: 10)
output after rendering pdf file is,
Solution 3:[3]
You have to add the printing module
https://pub.dev/packages/printing
dependencies:
printing: ^5.6.0
import the package in your dart file
import 'package:printing/printing.dart';
And set your theme with:
final pdf = pw.Document();
pdf.addPage(
pw.Page(
theme: pw.ThemeData.withFont(
base: await PdfGoogleFonts.varelaRoundRegular(),
bold: await PdfGoogleFonts.varelaRoundRegular(),
icons: await PdfGoogleFonts.materialIcons(),
),
pageFormat: PdfPageFormat.a4,
build: (pw.Context context) {
return pw.Center(
child: pw.Text("Hello World"),
);
},
),
);
The source of this answer is here
https://github.com/DavBfr/dart_pdf/blob/master/demo/lib/examples/resume.dart
Solution 4:[4]
To use Material Icons in Pdf package you just simply follow the code snippets down here.
Import material as mt and pdf as dynamic
import 'package:flutter/material.dart' as mt;
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
Now Try the following code it will work perfectly.
Icon(IconData(mt.Icons.check.codePoint),
color:
value PdfColors.grey,
size: 18,
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kiwiiiii |
| Solution 2 | Karthikeyan M |
| Solution 3 | |
| Solution 4 | Mehran Ullah |

