首页 > 解决方案 > 当 URL 作为参数传递给 .getDocument() 时,PDF.js 上缺少 PDF 错误

问题描述

我正在尝试访问一系列 PDF 链接并打印出它们的页数。目前,我正在 NodeJS localhost Web 服务器上尝试此代码,但出现此错误,message: 'Missing PDF "https://www.nice.com/Lists/PressReleases/Attachments/226/q2_2021_pr.pdf".', name: 'MissingPDFException'.

谁能帮我解决这个问题?此链接上有一个 PDF,在浏览器中导航到时可以看到。

    for (const pdfLink of pdfLinks) {
      console.log(pdfLink);
      let document = await pdfJS.getDocument(encodeURIComponent(pdfLink))
        .promise;
      let numberOfPages = document.numPages;
      console.log(numberOfPages);
    }
  } catch (error) {
    console.log(error);
  }

标签: node.jspdfpdfjs

解决方案


推荐阅读