1

I'm trying to use use PDFTron library "@pdftron/webviewer": "^6.2.3" , starting with this sample - https://github.com/PDFTron/webviewer-angular-sample

They have CoreControls namespace, described like this:

export declare namespace CoreControls {}

In my app.component.ts I'm using

import {CoreControls} from '@pdftron/webviewer';

Next I want to use this one:

ngOnInit() {
  CoreControls.createDocument('blabla');
}

And got this error

"ERROR TypeError: Cannot read property 'createDocument' of undefined".

In general I need to use their API without WebViewer, like here - https://www.pdftron.com/documentation/web/guides/get-file-data-without-viewer/ . But something is really wrong, maybe I don't understand angular right, or TS, or maybe PDFTron is not optimised for angular.

I don't understand what I don't understand.

Levsha
  • 455
  • 3
  • 18

1 Answers1

1

I think the CoreControls that is imported from the statement

import {CoreControls} from '@pdftron/webviewer';

is a type declaration, not the actual class. That can explain why CoreControls will be undefined when you try to access it.

To resolve this issue, you need to append the CoreControls script directly in the HTML file. Specifically, in this file https://github.com/PDFTron/webviewer-angular-sample/blob/master/src/index.html you would want to add a <script src=path></script> where the path is the location of the CoreControls.js in the npm package.

Hope this helps!