【问题标题】:How to add network image in pdf in flutter?如何在flutter中在pdf中添加网络图像?
【发布时间】:2021-10-27 11:02:32
【问题描述】:

大家好,我正在尝试在 pdf 中添加网络图像。 pdf是 使用 printing: ^5.5.0 插件创建。我正在运行时间 错误。请帮忙,在此先感谢。

previewpage.dart

    
      final pdf = pw.Document();
    
      MemoryImage images = [];
    
      Future _getImage() async {
        for (var i = 0; i < 2; i++) {
          var response = await http
              .get(Uri.parse("image url here"));
          final image =
              pw.RawImage(bytes: response.bodyBytes, width: 50, height: 100);
          images.add(image);
        }
        _writeOnPdf();
      }
  

【问题讨论】:

    标签: flutter pdf printing pdf-generation flutter-plugin


    【解决方案1】:

    使用打印:^5.5.0

    try {
                final provider = await flutterImageProvider(NetworkImage(
            "https://miro.medium.com/max/1000/1*ilC2Aqp5sZd1wi0CopD1Hw.png"));
                images.add(provider);
        } catch (e) {
                print("****ERROR: $e****");
                return;
        }
        
        pw.Center(
                child: pw.Padding(
                padding: const pw.EdgeInsets.all(3),
                child: pw.Image(
                  images[i],
                  width: 50,
                  height: 100,
                 ),
               ),
              )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      • 2023-01-18
      • 1970-01-01
      相关资源
      最近更新 更多