如何运行pdf.js节点示例?

huangapple go评论65阅读模式
英文:

How to run the pdf.js node examples?

问题

我正在尝试运行 pdf.js 的节点示例,例如 getinfo.js。但是出现了以下错误:

C:\Repositories\pdf.js>node getinfo.js
node:internal/modules/cjs/loader:1080
  throw err;
  ^
Error: Cannot find module 'pdfjs-dist/legacy/build/pdf.js'
Require stack:
- C:\Repositories\pdf.js\getinfo.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Repositories\pdf.js\getinfo.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Repositories\\pdf.js\\getinfo.js' ]
}

Node.js v18.16.1

这是我之前做的步骤:

git clone https://github.com/mozilla/pdf.js.git
cd pdf.js
npm install
npm install -g gulp-cli
gulp generic
gulp generic-legacy
cd examples
cd node
node getinfo.js -> 出现上述错误

那么,如何运行节点示例?为什么是 'pdfjs-dist/legacy/build/pdf.js'?是否可以更新到当前版本?是否有一个最新的示例供参考?

英文:

I am trying to run the pdf.js node examples, e.g. getinfo.js. However it fails with

C:\Repositories\pdf.js>node getinfo.js
node:internal/modules/cjs/loader:1080
  throw err;
  ^

Error: Cannot find module 'pdfjs-dist/legacy/build/pdf.js'
Require stack:
- C:\Repositories\pdf.js\getinfo.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\Repositories\pdf.js\getinfo.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Repositories\\pdf.js\\getinfo.js' ]
}

Node.js v18.16.1

This is what I did before:

git clone https://github.com/mozilla/pdf.js.git
cd pdf.js
npm install
npm install -g gulp-cli
gulp generic
gulp generic-legacy
cd examples
cd node
node getinfo.js -> gives error mentioned above

So, how to get the node examples running? Also, why is it 'pdfjs-dist/legacy/build/pdf.js'? Can one update to the current version / is there an up to date example to get started?

答案1

得分: 0

需要安装 pdfjs-dist。或者也可以这样操作:

运行 gulp dist-install 以生成 'pdfjs-dist' npm 包文件。

我可以调整示例并将

const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");

更改为

const pdfjsLib = require("pdfjs-dist/build/pdf.js");

无任何问题(对于 getinfo.js)。

英文:

Needed to install pdfjs-dist. Alternatively that might work too:

> Run gulp dist-install to generate 'pdfjs-dist' npm package files.

I could adapt the sample and change

const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
to
const pdfjsLib = require("pdfjs-dist/build/pdf.js");

without any issues (for getinfo.js)

huangapple
  • 本文由 发表于 2023年7月12日 20:56:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定