FLUTTER WEB - COUDNT GENERATE PDF DOC USING file.writeAsBytes

58 views
Skip to first unread message

vinay sharma

unread,
Feb 1, 2020, 5:43:47 AM2/1/20
to Flutter Development (flutter-dev)
// I have been trying to generate pdfs using pdf plugin and wrtie it to a pdf file
// but file.wrtieAsBytes not creating any files and its not even throwing any errors or giving any response


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));
}
Reply all
Reply to author
Forward
0 new messages