繁体   English   中英

如何从 flutter 的内部存储中打开 PDF 文件

[英]How to open PDF file from internal storage in flutter

用于代码的插件

native_pdf_view: ^4.0.1

出现错误的示例代码,我可以使用资产中的 pdf 文件,但无法从本地存储加载 pdf

    return Container(
      child: PdfView(
        controller:
            // sample,
            PdfController(
          document: PdfDocument.openFile(widget.path),
        ),
        onDocumentLoaded: (document) {
          setState(() {
            isLoaded = true;
          });
        },
        pageLoader: Center(child: CircularProgressIndicator()),
      ),
    );

错误,它说该文件未找到,但此文件路径是从现有文件中提取的

D/PDF_RENDER(  585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
D/PDF_RENDER(  585): OpenAssetDocument. Created file: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER(  585): OpenFileDocument. File: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER(  585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf

════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building PdfView(dirty, state: _PdfViewState#6990d):
Null check operator used on a null value

The relevant error-causing widget was
PdfView
lib/const/pdf.dart:23
When the exception was thrown, this was the stack
#0      _PdfViewState._buildLoaded
package:native_pdf_view/src/native_pdf_view.dart:172
#1      _PdfViewState.build
package:native_pdf_view/src/native_pdf_view.dart:205
#2      StatefulElement.build
package:flutter/…/widgets/framework.dart:4683
#3      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4566
#4      StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4738
...

请尝试其中任何一个

pdf:^3.3.0,flutter_full_pdf_viewer:^1.0.6,syncfusion_flutter_pdfviewer:^19.1.58-beta,syncfusion_flutter_pdfviewer_platform_interface:^19.1.58-beta

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM