问题描述
我遇到这些错误
- 发生异常。 _Exception(异常:读取PDF时出错!)从网址加载pdf
- 并且无法解析加载的pdf表单资产上的资产
这是我的代码
loadfile() async {
document = await PDFDocument.fromURL(
'http://www.africau.edu/images/default/sample.pdf');
setState(() {
document = document;
});
}
body: Center(child: PDFViewer(document: document)),
解决方法
import 'package:url_launcher/url_launcher.dart';
_launchURL() async {
const url = 'https://flutter.dev/exapmle.pdf';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
您可以不下载文件就使用它,可以使用url_launcher包从URL打开