Pdf.js: How to import the PDFViewer layer and what is its API?

Created on 24 Jul 2019  路  1Comment  路  Source: mozilla/pdf.js

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.

1-other

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jigskpatel picture jigskpatel  路  3Comments

zerr0s picture zerr0s  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

dmisdm picture dmisdm  路  3Comments