Pdf.js: Import pdf.js with typescript

Created on 12 Feb 2019  路  8Comments  路  Source: mozilla/pdf.js

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: NODE 10
  • Operating system and its version: LINUX/DOCKER
  • PDF.js version: pdfjs-dist 2.2.2
  • Is a browser extension: NO

Steps to reproduce the problem:

  1. Install pdfjs-dist with: npm install pdfjs-dist --save
  2. Install @types/pdfjs-dist with: npm install @types/pdfjs-dist --save-dev
  3. Import pdfjs-dist in a *.ts file: import { PDFJS } from 'pdfjs-dist';
  4. Use getDocument from PDFJS: PDFJS.getDocument('my.pdf')
  5. execute the code and see the error: _PDFJS is not defined_

What is the expected behavior?
PDFJS works on typescript

What went wrong?
PDFJS can't export correctly the lib on typescript

Link to a viewer:
not disponible

Work around:
Import PDFJS in this way

import { PDFJSStatic } from 'pdfjs-dist'; 
const PDFJS: PDFJSStatic = require('pdfjs-dist');

Most helpful comment

Does pdfjs provide it's own Typescript types somewhere else?

All 8 comments

2\. Install **@types/pdfjs-dist** with: `npm install @types/pdfjs-dist --save-dev`

Most likely, those types haven't been updated to handle PDF.js versions above 2.0.
However please note that that's a different library, which is not maintained here, hence this issue is unfortunately out-of-scope/invalid here.

@Snuffleupagus @timvandermeij Could you please reopen? @types/pdfjs-dist is totally off for version >= 2 and the Github repository does not have any issue tracker.

Install @types/pdfjs-dist with: npm install @types/pdfjs-dist --save-dev

As mentioned in https://github.com/mozilla/pdf.js/issues/10547#issuecomment-462675381, those are not in any way affiliated with Mozilla or the PDF.js project.

@types/pdfjs-dist

Again this is not related to https://github.com/mozilla/pdfjs-dist, but most likely you're actually referring to these ones: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pdfjs-dist

@types/pdfjs-dist should be maintained by mozilla/pdfjs-dist and/or mozilla/pdf.js contributors.

Only this contributors know the code and the functions and can write the required interfaces.

There are already open issues and even PRs for this, but so far the real demand for this is low and the PRs have not really been updated. If you think this is in fact important, please consider updating the existing PRs (such as #10575 which seems like a good approach since it attempts to generate it from the code itself) so they can be brought in a mergeable state.

Does pdfjs provide it's own Typescript types somewhere else?

why is this close? Where are the types provided and how can we include the library into a typescript project? Thank you

Duplicate of #7909 and that was fixed just yesterday.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smit-modi picture smit-modi  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

hp011235 picture hp011235  路  4Comments

kleins05 picture kleins05  路  3Comments