Hi, it's unclear to me how to import the PDFViewer class in Node. I have installed PDFJS from NPM (after figuring out the arkane NPM package name).
I tried this:
import PDFJS from 'pdfjs-dist';
import * as viewer from 'pdfjs-dist/web/pdf_viewer';
But this throws:
ReferenceError: document is not defined
at Object.<anonymous> (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:3169:1)
at __w_pdfjs_require__ (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:52:30)
at Object.<anonymous> (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:2997:1)
at __w_pdfjs_require__ (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:52:30)
at Object.<anonymous> (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:236:20)
at __w_pdfjs_require__ (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:52:30)
at D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:116:18
at D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:119:10
at webpackUniversalModuleDefinition (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:25:20)
at Object.<anonymous> (D:\<project>\node_modules\pdfjs-dist\web\pdf_viewer.js:32:3)
I am using node --experimental-modules index.mjs
so that I can use ESM.
What is the right way to use the viewer? Also, what is its API? The https://github.com/mozilla/pdf.js/blob/master/src/display/api.js file doesn't seem to describe anything from this layer.
it's unclear to me how to import the
PDFViewer
class in Node.
If by that you mean actually running the code in Node.js that won't work unfortunately, since the viewer components are generally written for usage in web browsers (i.e. assuming that globals such as e.g. window
and document
are present and working correctly).
Also, what is its API?
Please refer to the JSDoc comments in https://github.com/mozilla/pdf.js/blob/master/web/base_viewer.js