question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import pdf.js with typescript

See original GitHub issue

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');

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

30reactions
Bluejaniscommented, Jul 11, 2019

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

11reactions
MickLcommented, May 20, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Build a TypeScript PDF Viewer with PDF.js - PSPDFKit
In this tutorial, we'll show how to build a TypeScript PDF viewer with PDF.js, one of the most popular open source libraries for...
Read more >
How can I get TypeScript to load the PDF.js NPM module and ...
I'm trying to import PDF. JS into a TypeScript project. I'm using the DefinitelyTyped bindings for pdfjs-dist , installed via npm install @ ......
Read more >
How to Build a PDF Viewer with TypeScript & PDF.js | PDFTron
In this article, we show how to create a PDF viewing app using PDF.js and TypeScript.
Read more >
Typescript Pdfjs Testyy - StackBlitz
import * as pdfjsLib from 'pdfjs-dist';. // Write TypeScript code! const appDiv: HTMLElement = document. getElementById('app');. appDiv.innerHTML = `.
Read more >
@types/pdfjs-dist - npm
Stub TypeScript definitions entry for pdfjs-dist, which provides its own types definitions. Latest version: 2.10.378, last published: a year ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found