[英]Flutter: How to open PDF document with specific page range
我想打开一个具有特定页面范围的 PDF 文档。 就像 PDF 有 10 页一样。 然后我想从第 3 页打开到第 7 页。
我已经尝试了多个在线可用的软件包。 不提供此功能。
例如:
flutter_plugin_pdf_viewer 1.0.7 - 这提供了选项,但这有很多依赖问题,因此我不想使用它。
因此,请向我推荐一些库,或者如果有人有一些与此相关的代码,请提供给我。 或者,如果有任何其他最佳方法可以满足给定要求,那么也建议我。
这个插件可以帮助我打开带有特定页码的 pdf。
第 1 步:加载文档
Future<PDFDocument> _getDocument() async {
if (await new File('../path_of_file').exists()) {
file = 1; // exist
return PDFDocument.openFile('../path_of_file');
} else {
setState(() {
showAppBar = true;
file = 0; // Does not exist
});
}
}
第二步:用特定的页码初始化
@override
void initState() {
super.initState();
showAppBar = false;
pageController = PageController(
initialPage: 1, //page number in the initializer
);
}
第 3 步:使用以下内容访问构建小部件
return FutureBuilder<PDFDocument>(
future: _getDocument(),
builder: (_, snapshot) {
if (snapshot.hasData) {
return PDFView(
controller: pageController,
document: snapshot.data,
);
}
if (snapshot.hasError) {
return Center(
child: Text(
'PDF Rendering does not '
'support on the system of this version',
),
);
}
return Center(child: CircularProgressIndicator());
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.