小编Ana*_*hna的帖子

错误参数类型“PdfImage”无法分配给参数类型“ImageProvider”

我正在尝试使用 flutter 中的屏幕截图和 pdf 插件从屏幕截图制作 pdf。

当我将 Uint8List 传递给 pdf 创建函数时,我收到错误PdfImage.file(pdf.document, bytes: screenShot The argument type 'PdfImage' can't be分配给参数类型 'ImageProvider' The code to conversion to pdf is

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());
  }

Run Code Online (Sandbox Code Playgroud)

并将屏幕截图传递给 pdf 函数如下

 Uint8List _imageFile;
screenshotController.capture().then((Uint8List image) {
                                            //Capture Done
                                            setState(() {
                                              _imageFile …
Run Code Online (Sandbox Code Playgroud)

pdf-generation dart flutter flutter-packages

5
推荐指数
1
解决办法
2214
查看次数

标签 统计

dart ×1

flutter ×1

flutter-packages ×1

pdf-generation ×1