I want to print Hindi language in my PDF, I've also tried using Raleway-Regular.ttf font by Google but it also didn't worked.
final font = await rootBundle.load("fonts/ARIAL.TTF");
final ttf = pw.Font.ttf(font);
pdf.addPage(
pw.MultiPage(
pageFormat: PdfPageFormat.a4,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context){
return <pw.Widget>[
pw.Center(
child: pw.Text("मेन",style: pw.TextStyle(fontSize: 16,font: ttf))
),
pw.SizedBox(height: 20),
pw.Center(
child: pw.Text("ABC",style: pw.TextStyle(fontSize: 16))
),
),
),
I'm getting following Error:
***I/flutter (24862): Cannot decode the string to Latin1.
I/flutter (24862): This font does not support Unicode characters.
I/flutter (24862): If you want to use strings other than Latin strings, use a TrueType (TTF) font instead.
I/flutter (24862): See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
I/flutter (24862): ---------------------------------------------
E/flutter (24862): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid argument (string): Contains invalid characters.: "मेन"
I am also facing the same error its because the fonts you are using does not support that language , if you want to use hindi language then you can use hind-regular.ttl font it supports both the fonts hindi and english.
here is the example what i got.
// step 1- add font locatin in pubspec
fonts:
- family: hind
fonts:
- asset: assets/hind.ttf
//step 2-
final pdf = pw.Document();
final font = await rootBundle.load("assets/hind.ttf");
final ttf = pw.Font.ttf(font);
then just apply this ttf in the fontStyle
packages i m using -
import 'package:universal_html/html.dart' as html;
import 'package:pdf/widgets.dart' as pw;
universal_html: ^1.2.3
enter image description here
pdf: ^1.11.1
Some issues are there with Unicode translations . Please take care of it https://github.com/DavBfr/dart_pdf/issues/198
You can use syncfusion pdf library (You need to buy subscription). You will get all kind of support including search,rtl, unicode support .
final font = await rootBundle.load("assets/fonts/hind.ttf");
final ttf = Font.ttf(font);
final pdf = pw.Document();
pw.Text(
'Your text',
textDirection:TextDirection.rtl, // If you need in opp direction like urdu
style: pw.TextStyle(
font: ttf,))
If someone still has this problem
final data = await rootBundle.load('assets/fonts/opensans_regular.ttf');
final dataint = data.buffer.asUint8List(data.offsetInBytes,data.lengthInBytes);
final PdfFont font = PdfTrueTypeFont (date,12);
Most of the language not works well with the flutter pdf plugin
In Tamil language, I face problems when two characters merge.
so, i modified the tff with available tools and replaced that character with that character.
as the result, i can able to get the output
String path = 'assets/custom_Anand_MuktaMalar.ttf';
pw.Font? tamilFont = pw.Font.ttf(await rootBundle.load(path));
pw.Text('உவவுமதி உருவின் ஓங்கல் வெண்குடை'.toPrintPdf)
pdf.addPage(
pw.Page(
theme: pw.ThemeData(defaultTextStyle: pw.TextStyle(font: tamilFont)),
));
for further ref, you can see my project:
https://github.com/anandsubbu007/anand-work/tree/BLOC/tamil_pdf
Related
The bounty expires in 3 days. Answers to this question are eligible for a +50 reputation bounty.
mirkancal wants to draw more attention to this question.
In ios/android apps emojis are shown correctly. But using any web-browser (e.g. Chrome) the emoji appears in black and white. I also tried different Font-Families but with the same result.
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text('Enjoy! 🥳 If there\'s any question')
),
);
}
}
Use Noto Color Emoji from google (follow this steps):
Download the font Download Noto Color Emoji
Added it to pubspec.yaml `flutter:
fonts:
family: Noto Color Emoji
fonts:
asset: assets/fonts/NotoColorEmoji-Regular.ttf`
And in TextStyle class use it like this TextStyle( fontFamilyFallbackm: [ 'Apple Color Emoji', 'Noto Color Emoji', ], )
Unlike that try to:
. Delete web folder
. Update flutter by using command flutter upgrade
. Run command flutter create .
issue
I want to put icons like SVG.
But I can't put it.
The dart file generated by the Flutter custom icons generator.
class WDLogo {
WDLogo._();
static const _kFontFam = 'WDLogo';
static const String? _kFontPkg = null;
static const IconData arrow_back = IconData(0xe801, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData arrow_forward = IconData(0xe802, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData menu = IconData(0xe803, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
pubspec.yaml
fonts:
- family: WDLogo
fonts:
- asset: assets/fonts/WDLogo.ttf
icon widget
"Icon(WDLogo.arrow_back))"
https://www.fluttericon.com/
SVG (Correct icon)
Mac folder
Flutter custom icons generator
Mac font preview
You need to add your fonts to asset folder and defined it on pubspec.yaml file like this
flutter:
fonts:
- family: MyFlutterApp
fonts:
- asset: fonts/MyFlutterApp.ttf
first add plugin ,link : https://pub.dev/packages/fluttericon/install
to your pubsepec.yaml file. after that import file.
then
Call Your icons like this
final myIcons = const <Widget>[
const Icon(Typicons.attention),
const Icon(Fontelico.emo_wink),
const Icon(Linecons.globe),
];
DONT USE LIKE THIS "Icon(WDLogo.arrow_back))",
if You need to use SVG , you can use this Flutter svg plugin for that ,
link for plugin https://pub.dev/packages/flutter_svg
final String assetName = 'assets/image.svg';
final Widget svg = SvgPicture.asset(
assetName,
semanticsLabel: 'Acme Logo'
);
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.
The below are packages that i am using.
pdf: ^3.8.1
printing: ^5.9.1
Appreciate the response!.
Thanks.
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.: "")
To use Material Icons in Pdf package you just 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 take the Icon from the Material library and pass its codepoints to IconData Constructor in PDF Library now you can easily use the IconData instance in PDF Icon() class.
Icon(IconData(mt.Icons.check.codePoint),
color:
value PdfColors.grey,
size: 18,
)
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
)
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
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,
I'd like to be able to add an svg image to the AppBar in my flutter application. I've used a package called flutter_svg to add the svgs to the project, however the images do not appear in the project. The code in the main is as follows:
class FrontpageState extends State<Frontpage> {
//mother widget
Widget build(BuildContext context) {
final Widget svgJuro = SvgPicture.asset(juro);
final Widget svgBanco = SvgPicture.asset(banco, semanticsLabel: 'Banco');
final Widget svgGoverno =
SvgPicture.asset(titulos, semanticsLabel: 'Titulos');
final Widget svgFundos = SvgPicture.asset(fundos, semanticsLabel: 'Fundos');
final Widget svgQuestao =
SvgPicture.asset(questao, semanticsLabel: 'Questão');
return Scaffold(
appBar: AppBar(
shadowColor: jBrown100,
title: Align(
alignment: Alignment(-0.6, 0),
child: Text('JURAS?',
style: GoogleFonts.roboto(
color: jBlack100,
fontSize: 48,
fontWeight: FontWeight.w700,
letterSpacing: -2))),
actions: [
new IconButton(icon: svgJuro, onPressed: null, color: jPink100)
],
));
}
The code in the dependencies and a separate assets dart file:
dependencies:
flutter:
sdk: flutter
google_fonts: ^1.1.1
flutter_svg: ^0.19.1
//assets.dart
final String juro = 'imgAsset/juro.svg';
final String banco = 'imgAsset/banco.svg';
final String titulos = 'imgAsset/governo.svg';
final String fundos = 'imgAsset/fundos.svg';
final String questao = 'imgAsset/questao.svg';
I put the SVG in the actions because I want to animate the SVG in the future. I think the only way I can achieve this is through a custom appbar using a container, here is the design I am trying to implement, please give me any suggestions regarding making this design a reality:
Thank you in advance for your help.
Just make sure that your images are .svg format [use a convertor to convert to .svg format]. I had a similar issue as the one mentioned when trying to display a .png image.
1.Enable Custom assets. Then move your svg file to assets folder.
2.Run this command:
With Flutter:
$ flutter pub add flutter_svg
3.Now in your Dart code, you can use:
import 'package:flutter_svg/flutter_svg.dart';
4.Code Like This:
title: SvgPicture.asset('./assets/traveler.svg'),