Flutter:如何打开具有特定页面范围的PDF文档 [英] Flutter: How to open PDF document with specific page range

查看:78
本文介绍了Flutter:如何打开具有特定页面范围的PDF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开具有特定页面范围的PDF文档.就像PDF有10页一样.然后我要从第3页打开到第7页.

I want to open a PDF document with specific page ranges. Like if a PDF have 10 pages. then i want to open from Page 3 to Page 7.

我尝试了多个可在线获得的软件包.不提供此功能.

I have tried multiple packages which are available online. which are not providing this functionality.

例如:

flutter_plugin_pdf_viewer 1.0.7 -这提供了选项,但是有很多选择依赖性问题,因此我不想使用它.

flutter_plugin_pdf_viewer 1.0.7 - This provides the options, but this has a lot of dependency issues, Therefore i don't want to use this.

pdf_viewer_plugin 1.0.0 + 2

因此,请向我推荐一些库,或者如果有人有与此相关的代码,请向我提供.或者,如果还有其他最佳方法可以满足给定的要求,那么也建议我.

Therefore please recommend me some library, or if somebody has some code related to this, please provide me that. Or if there is any other best approach to meet the given requirement, then suggest me also.

推荐答案

插件可帮助我打开具有特定页码的pdf.

This plugin helps me to open the pdf with the specific page number.

第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
      });
    }
  }

第2步:使用特定的页码进行初始化

Step 2 : Initialize with the specific page number

@override
  void initState() {
    super.initState();
    showAppBar = false;
    pageController = PageController(
      initialPage: 1,  //page number in the initializer
    );
  }

第3步:使用以下内容访问构建小部件

Step 3 : Access in the build widget with the following

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());
                        },
                      );

这篇关于Flutter:如何打开具有特定页面范围的PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆