尝试在flutter中创建不同语言的pdf

Pra*_*pta 3 pdf fonts flutter

我想在我的 PDF 中打印印地语,我也尝试过使用 Google 的 Raleway-Regular.ttf 字体,但它也不起作用。

\n
final font = await rootBundle.load("fonts/ARIAL.TTF");\nfinal ttf = pw.Font.ttf(font);\n\npdf.addPage(\n  pw.MultiPage(\n    pageFormat: PdfPageFormat.a4,\n    margin: pw.EdgeInsets.all(32),\n    build: (pw.Context context){\n    return <pw.Widget>[\n      pw.Center(\n        child: pw.Text("\xe0\xa4\xae\xe0\xa5\x87\xe0\xa4\xa8",style: pw.TextStyle(fontSize: 16,font: ttf))\n      ),\n      pw.SizedBox(height: 20),\n      pw.Center(\n      child: pw.Text("ABC",style: pw.TextStyle(fontSize: 16))\n    ),\n  ),\n),\n
Run Code Online (Sandbox Code Playgroud)\n

我收到以下错误:

\n

***I/flutter (24862): 无法将字符串解码为 Latin1。\nI/flutter (24862): 此字体不支持 Unicode 字符。\nI/flutter (24862): 如果您想使用拉丁语以外的字符串字符串,请改用 TrueType (TTF) 字体。\nI/flutter (24862):请参阅https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management \nI/flutter (24862):----- ----------------------------------------------------\nE/flutter (24862): [错误:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:无效参数(字符串):包含无效字符。:“\xe0\xa4\xae\xe0\xa5\x87\xe0\xa4\xa8”

\n
\n

小智 6

我也面临同样的错误,因为您使用的字体不支持该语言,如果您想使用印地语,那么您可以使用hind-regular.ttl字体,它支持印地语和英语字体。

这是我得到的例子。

// 第 1 步 - 在 pubspec 中添加字体定位

字体:- 系列:后字体:- 资产:assets/hind.ttf

//第2步-

最终 pdf = pw.Document();

final font = await rootBundle.load("assets/hind.ttf");

final ttf = pw.Font.ttf(font);
Run Code Online (Sandbox Code Playgroud)

然后只需在 fontStyle 中应用这个 ttf

我使用的软件包 -

将'package:universal_html/html.dart'导入为html;

导入 'package:pdf/widgets.dart' 作为 pw;

universal_html:^1.2.3 在此处输入图像描述 pdf:^1.11.1