pdf 包无法在 Flutter 虚拟主机中运行

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

我在我的 Flutter Web 项目中使用了 pdf 包。当我在调试或发布模式下运行它时,它完全可以工作,但是当部署网络时,它就无法工作。我们可以看到它是可以点击的,但是点击后没有任何反应。

目前,当我单击按钮时,我可以看到它被单击,但没有任何反应。我想点击生成pdf,只有部署web时才会出现这个问题

我尝试将此代码放入index.html文件中,但没有任何反应。

<script type="text/javascript">
  pdfjsLib.GlobalWorkerOptions.workerSrc =
    "https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
  pdfRenderOptions = {
    // where cmaps are downloaded from
    cMapUrl: "https://cdn.jsdelivr.net/npm/[email protected]/cmaps/",
    // The cmaps are compressed in the case
    cMapPacked: true,
    // any other options for pdfjsLib.getDocument.
    // params: {}
  };
</script>
flutter dart web pub.dev
1个回答
0
投票

我在代码中使用了一种字体作为

  static getGujaratiFont() async {
      final font = await rootBundle.load("fonts/NotoSansGujarati.ttf");
      gujaratiFont = pw.Font.ttf(font);

}

我在 pubspec.yaml 文件中的路径是

  assets:
    - assets/fonts/NotoSansGujarati.ttf

所以,“rootBundle”是在调试 Web 时添加自动资源,但是当部署 Web 时,我必须将字体中的路径设置为

rootBundle.load("assets/fonts/NotoSansGujarati.ttf");
然后它才能工作

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