我正在尝试在Flutter中显示我之前从服务器下载的PDF文件。我已经尝试过flutter_full_pdf_viewer和advance_pdf_viewer了。两个库都显示了正确的页数,但页面都是白色的。
有人知道为什么吗?无论我是在iOS或安卓上运行,还是在模拟器或真实设备上运行,都没有区别。
class _PdfPageState extends State<PdfPage> {
String pathPDF = "";
File file;
PDFDocument doc = null;
@override
void initState() {
super.initState();
WeeklyReportsRepository( userRepository: UserRepository()).loadWeeklyReport(widget.weeklyReport.filename).then((file) {
setDoc(file);
});
}
Future<void> setDoc(File file) async {
var doc1 = await PDFDocument.fromFile(file);
setState(() {
doc = doc1;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.white),
title: Text(
"Wochenbericht",
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
color: Theme
.of(context)
.backgroundColor,
child: (doc == null) ? Center(child: CircularProgressIndicator()) :
PDFViewer(document: doc,
scrollDirection: Axis.vertical,),
),
);
}
}发布于 2020-09-28 05:30:38
一切似乎都是正确的,但您是否可以尝试查看从您的计算机或链接的pdf,也尝试查看该pdf的特定页面。Package document尝试从资源、网址或文件加载,如链接所示。如果这些方式工作,您在服务器端会遇到问题。
发布于 2021-01-30 16:07:51
在我的例子中,它是UTF-8字符的文件名。一旦我将pdf文件名改为英文字母,无论是否使用.pdf扩展名,advance_pdf_viewer都可以读取它。
发布于 2021-03-14 23:22:27
确保pdf文件是字母表文件,而不是转换为Pdf的图片。
https://stackoverflow.com/questions/64093283
复制相似问题