【发布时间】:2020-05-17 20:48:01
【问题描述】:
我一直在尝试使用 pdf 插件生成 pdf,并使用 file.writeAsBytes 将其写入 pdf 文件,但它没有创建任何文件,甚至没有抛出任何错误或给出任何响应。我正在使用 pdf 插件并尝试效法它的榜样。
链接https://pub.dev/packages/path#-example-tab-
void makePdf() async {
final pw.Document doc = pw.Document();
pw.Font font = pw.Font.ttf(await rootBundle.load('assets/Exo-Bold.ttf'));
doc.addPage(
pw.Page(
pageFormat: pdf.PdfPageFormat.a4,
build: (pw.Context context) {
return pw.Center(
child: pw.Text(
"Hello World",
style: pw.TextStyle(font: font),
),
); // Center
},
),
);
final file = File("ms.pdf");
List<int> data = doc.save();
// print(data);
file.writeAsBytes(data).then((file) {
print("done");
}).catchError((e) => print(e));
}
【问题讨论】:
标签: flutter dart flutter-web