【问题标题】:Image to pdf convertion in flutter颤动中的图像到pdf转换
【发布时间】:2020-10-31 08:34:41
【问题描述】:

我目前正在使用 Flutter 开发照片扫描仪应用程序,并寻找一种将图像转换为 pdf 的方法。如果有人帮助我,那就太好了

【问题讨论】:

    标签: image flutter pdf


    【解决方案1】:

    使用pdf 包:

    dependencies:
      pdf: ^1.9.0
    

    从文件中加载图像:

    final pdf = pw.Document();
    final image = PdfImage.file(
      pdf.document,
      bytes: File('test.webp').readAsBytesSync(),
    );
    
    pdf.addPage(pw.Page(
        build: (pw.Context context) {
          return pw.Center(
            child: pw.Image(image),
          ); // Center
        })); 
    

    然后创建pdf:

    final file = File("example.pdf");
    await file.writeAsBytes(pdf.save());
    

    【讨论】:

    • 但是如何传递我已经使用手机相机拍摄的图像。错误'类型文件不能传递给类型字符串
    • @Dhanush 您应该从该图像创建字节文件
    • 你能告诉我怎么做吗
    猜你喜欢
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    相关资源
    最近更新 更多