SfPdfViewer.asset() 在 Chrome 中不显示 PDF(syncfusion_flutter_pdfviewer 包);我是颤振新手

问题描述 投票:0回答:1

使用 SfPdfViewer.asset 功能时,Chrome 浏览器中不显示 PDF。

以下是显示页面时使用的构建方法:

Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("My PDF Document"),
        ),
        body: SingleChildScrollView(
          child: SfPdfViewer.asset('assets/patientForm.pdf'),
        ),
      ),
    );
  }

PatientForm.pdf 添加到文件根目录的 asset 文件夹中,并添加到 pubspec.yaml (在 flutter 下),如下所示:

 assets:
    - assets/patientForm.pdf

页面加载后,仅显示 AppBar,页面其余部分为空白。

我仔细检查了文件名的拼写,没有出现 404 错误,这意味着文件已找到。代码还有错误吗?

我尝试清理flutter并重新运行它,但仍然不起作用。

flutter dart pdf syncfusion
1个回答
0
投票

我们怀疑您可能错过了 web/index.html 文件中的脚本部分。请在 web/index.html 文件中包含以下脚本。

UG 文档:https://help.syncfusion.com/flutter/pdf-viewer/getting-started#add-the-flutter-pdf-viewer-to-an-application

<script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
<script type="text/javascript">    
   pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js";    
</script>

注意:由于 SfPdfViewer 小部件已经可以滚动,因此不建议在 SingleChildScrollView 小部件中使用 SfPdfViewer 小部件。

© www.soinside.com 2019 - 2024. All rights reserved.