pdfjs_dist_1.default.getDocument is not a function

137 views Asked by At

I am building an Outlook add-in and want to render a small version of a pdf inside it.

For this i have choosen pdf.js, because in the add-in i only have the browser context.

But i get the following error:

Uncaught TypeError TypeError: pdfjs_dist_1.default.getDocument is not a function at (a:\erpol\src\taskpane\taskpane.ts:284:24) at step (localhost꞉3000/taskpane.js:332:17) at (localhost꞉3000/taskpane.js:281:14) at (localhost꞉3000/taskpane.js:255:67) at webpack_modules../src/taskpane/taskpane.ts.__awaiter (localhost꞉3000/taskpane.js:237:10) at displayPDFThumbnail (localhost꞉3000/taskpane.js:605:10) at (a:\erpol\src\taskpane\taskpane.ts:355:13) at (appsforoffice.microsoft.com/lib/1.1/hosted/outlook-win32-16.02.js:20:204418) at a (appsforoffice.microsoft.com/lib/1.1/hosted/outlook-win32-16.02.js:20:205014) at (appsforoffice.microsoft.com/lib/1.1/hosted/outlook-win32-16.02.js:20:205402) at agaveResponseCallback (/VM46947590:1:8812) at window.agaveHostCallback (/VM46947590:1:11244) at (/VM46947597:1:8)

This is basically my code inside the taskpane.ts:

import pdfjslib from 'pdfjs-dist';
...
const pdf = pdfjslib.getDocument({data: pdfDataAsB64});

I also tried these imports, which did not work:

import * as pdfjs from 'pdfjs-dist';
import { getDocument } from 'pdfjs-dist/webpack';
import * as pdfjslib from "pdfjs-dist/build/pdf.mjs";
var pdfjslib = require('pdfjs-dist');

I have installed pdfjs with npm i pdfjs-dist. Intelli sense also works an i can ctrl+click on get Document and can see the api.d.ts file:

export function getDocument(src: string | URL | TypedArray | ArrayBuffer | DocumentInitParameters): PDFDocumentLoadingTask;
export class LoopbackPort {
    postMessage(obj: any, transfer: any): void;
    addEventListener(name: any, listener: any): void;
    removeEventListener(name: any, listener: any): void;
    terminate(): void;
    #private;
}

One last thing to note is that Outlook add-ins use webpack.

Update:

If i import the pdf.mjs inside the taskpane.html i can render the hello world example https://jsfiddle.net/pdfjs/9engc9mw/

Why can't i use the pdfjs-dist inside my taskpane.ts?
https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website

0

There are 0 answers