实施 PDF.js 查看器示例

Implementing PDF.js Viewer example

我 运行 遇到了一个问题,试图实施 PDF.js 查看器演示 here,但我 运行 遇到了一个问题,即某些属性没有放。检查控制台有两个错误:

第一个错误:

app.js:883 Uncaught (in promise) TypeError: Cannot read property 'setPagesCount' of null
at Object.load (app.js:883)
at app.js:666

第二个错误:

app.js:870 Uncaught (in promise) TypeError: Cannot read property 'then' of undefined
at app.js:870

我已经尝试通过自己深入研究代码来解决这个问题,并将它与示例进行比较,但没有成功。我也在网上四处寻找,试图弄清楚为什么会发生这种情况,但仍然空手而归。在我看来 this.toolbar 没有设置 first error 中的任何内容,但我不明白为什么会这样。

通过在线查看,我相信我设置正确,但不是 100% 肯定。这是我的设置:

<script type="text/javascript">
    $(document).ready(function () {
        var pdfDoc = '@pdf';

        // Open the default file after the document is ready. Otherwise, PDFViewerApplication probably won't exist.
        PDFViewerApplication.open(pdfDoc);
    });
</script>

有没有人以前经历过这种情况并且能够提供帮助?如果没有,有谁知道我可以从哪里开始看?

另外请注意,我已将文件移出它们原来的 buildweb 目录。我以为我更改了 viewer.js 中的配置路径以适应这一点,但也许我错过了一个?

看来我的问题是我没有在 HTML 中为 locale.properties 添加 link 资源。原来我得到的第一个错误更像是一个转移注意力的错误,并且能够通过关注第二个错误来解决这个问题。

我添加了这个:

<link rel="resource" type="application/l10n" href="[your path to]/locale/locale.properties">

查看器的所有 HTML 所在的位置并立即加载。