问题描述
我正在尝试在Flutter中显示PDF文件,该文件以前是从服务器下载的。 我已经尝试了Flutter_full_pdf_viewer和advance_pdf_viewer。这两个库都向我显示了正确的页面数,但是页面都是白色的。
有人知道为什么吗?如果我在iOS或Android或仿真器或真实设备上运行它,没有什么区别。
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,);
}
}
解决方法
一切似乎都正确,但是您可以尝试通过计算机或链接查看pdf格式,还是尝试查看pdf的特定页面。 Package document尝试从资产,URL或文件中加载,如链接中所示,如果这些方法都可以解决服务器方面的问题。
,就我而言,它是 UTF-8 字符的文件名。一旦我将 pdf 文件名更改为英文字母,advance_pdf_viewer
可以使用或不使用 .pdf 扩展名阅读。
确保 Pdf 文件是字母文件,而不是转换为 pdf 的图片。