【发布时间】:2021-11-03 05:20:33
【问题描述】:
我正在尝试使用 Flutter 中的屏幕截图和 pdf 插件从屏幕截图制作 pdf。
当我将 Uint8List 传递给 pdf 创建函数时,PdfImage.file(pdf.document, bytes: screenShot 出现错误 无法将参数类型“PdfImage”分配给参数类型“ImageProvider”转换为 pdf 的代码是
Future getPdf(Uint8List screenShot) async {
pw.Document pdf = pw.Document();
pdf.addPage(
pw.Page(
pageFormat: PdfPageFormat.a4,
build: (context) {
return pw.Expanded(
child: pw.Image(PdfImage.file(pdf.document, bytes: screenShot), fit: pw.BoxFit.contain)
);
},
),
);
File pdfFile = File('Your path + File name');
pdfFile.writeAsBytesSync(await pdf.save());
}
并将屏幕截图传递给 pdf 函数如下
Uint8List _imageFile;
screenshotController.capture().then((Uint8List image) {
//Capture Done
setState(() {
_imageFile = image;
});
}).catchError((onError) {
print(onError);
});
getPdf(_imageFile);
},
谁能帮我解决这个问题?
【问题讨论】:
-
MemoryImage 呢?
-
@PeterKoltai 对不起,我没听明白!
-
你使用this包吗?
-
@PeterKoltai 是的,该软件包用于将该屏幕截图转换为 pdf,这是我收到错误的部分,您可以在上面的代码中看到它。
-
这个包有一个叫MemoryImage的方法,我链接了它,不像
pw.Image它接受Uint8List作为输入,试试看。
标签: flutter dart pdf-generation flutter-packages