请注意,我很难在 CDN 上使用 pdf.js 显示包括日语在内的 PDF 文件。
提取和安装 Prebuild zip 时可能几乎相同。

如果你搜索它,你会找到在某种程度上使用viewer.html的方法,但是在编写脚本时很难找到关于阅读pdf.js本身的信息。

使用的版本:pdf.js 2.16.105

官方例子

  • 例子
    最低限度。仅此一项,没有CMAP设置,所以不会显示日语等。
  • GitHub 存储库示例
    有品种吗?(我没看过多少)

基本设定

当您在控制台中看到Deprecated API usage: No "GlobalWorkerOptions.workerSrc" specified.

pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@2.16.105/build/pdf.worker.js';

可以写成(官方例子里也有这个描述)

日本显示器

到控制台
Warning: loadFont - translateFont failed: "UnknownErrorException: CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.".
Warning: Error during font loading: CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.
显示,不画日语

const loadingTask = pdfjsLib.getDocument({
    url: 'sample.pdf',
    cMapUrl: "https://unpkg.com/pdfjs-dist@2.16.105/cmaps/",
    cMapPacked: true,
});

明确指定 cMap,如 .

其他参考文章


原创声明:本文系作者授权爱码网发表,未经许可,不得转载;

原文地址:https://www.likecs.com/show-308628937.html

相关文章: