flutter - 在 Flutter 中将 base64 字符串转换为 PDF 文件
问题描述
我正在尝试显示 PDF 文件。但是我从服务器收到的 PDF 文件采用 Base64 字符串格式。有什么方法可以直接将 Base64 字符串显示到 PDF 查看器或 WebView 中而不将其保存到文件中。
解决方案
检查这个:https ://stackoverflow.com/a/55599926/305135
(以下代码是从上面的链接复制的)
这应该将 base64 编码的 pdf 数据转换为字节数组。
import 'packages:dart/convert.dart';
List<int> pdfDataBytes = base64.decode(pdfBase64)
.map((number) => int.parse(number));
代码应该大致是这样的:
导入“包:pdf/pdf.dart”;导入“包:图像/image.dart”;
...
Image img = decodeImage(pdfDataBytes);
PdfImage image = PdfImage(
pdf,
image: img.data.buffer.asUint8List(),
width: img.width,
height: img.height);
// Display it somehow
...
推荐阅读
- java - Java AES 解密异常:javax.crypto.BadPaddingException:
- java - Spring Boot 从 AWS 参数存储读取参数
- mysql - 如何使用触发器复制表
- java - 无效参数错误使用 NetShareAdd windows Api 使用 JNA 库
- angular - Primeng Autocomplete - 不使用 Angular 中的反应形式修补值
- elasticsearch - Filebeat 缓冲区控制
- tomcat - 如何将流量从 Nginx 入口路由到应用程序 Tomcat 服务器
- jmeter - 使用 Jmeter 连接雪花 JDBC 连接器时收到错误
- r - 识别事件前后的行
- java - 如何在数据库连接中正确使用 try-with-resources?