Error with loadDocument

198 views
Skip to first unread message

Volker Andres

unread,
May 9, 2017, 12:01:05 PM5/9/17
to PDFTron WebViewer
Hi

I am having some troubles with loading documents with loadDocument. We have the use case, that documents have to be loaded from a server. They are protected by Basic Auth. This code gives an error:

let webviewer = new PDFTron.WebViewer({
    type: "html5mobile",
    path: "assets/js/",
    documentId: "xod",
    documentType: "xod",
    enableAnnotations: true,
    streaming: false,
    mobileRedirect: false,
    enableOffline: false,
    autoCreate: true
}, this.pdftron.nativeElement);

let headers = {
    'Authorization': 'Basic ' + btoa(this.user.username + ':' + this.user.password),
    'Content-Type': 'application/x-www-form-urlencoded'
};

webviewer.loadDocument('/api/v1/asset/128-xod', {customHeaders: headers});

The following error occurs: TypeError: this.getInstance(...) is undefined Stack-Trace: loadDocument@http://10.0.1.199:8100/assets/js/WebViewer.js:752:9

This code works, but it is not very nice to wait 3 seconds

let webviewer = new PDFTron.WebViewer({
type: "html5mobile",
path: "assets/js/",
documentId: "xod",
documentType: "xod",
enableAnnotations: true,
streaming: false,
mobileRedirect: false,
enableOffline: false,
autoCreate: true
}, this.pdftron.nativeElement);

let headers = {
'Authorization': 'Basic ' + btoa(this.user.username + ':' + this.user.password),
'Content-Type': 'application/x-www-form-urlencoded'
};

window.setTimeout(() => {
webviewer.loadDocument('/api/v1/asset/128-xod', {customHeaders: headers});
}, 3000);


I am happy for any advice.

Best Regards
Volker Andres

Dhaya Benmessaoud

unread,
May 9, 2017, 1:00:57 PM5/9/17
to PDFTron WebViewer
Hi, in my implementation I wait for the ready event to be triggered on the container, before loading a document. In your case that would be something like this:

    $(this.pdftron.nativeElement).on('ready', () => {
        webviewer.loadDocument(/*...*/);
    });

Since it's a custom event, it can only be caught using jQuery, as far as I know 😕.

Justin Jung

unread,
May 9, 2017, 4:16:08 PM5/9/17
to PDFTron WebViewer on behalf of Dhaya Benmessaoud
Hello,

Yup! What Dhaya said is the correct way to do it. You would need to wait for the ready event to call loadDocument.

Justin Jung
Software Developer
PDFTron Systems Inc.

Volker Andres

unread,
May 12, 2017, 11:34:23 AM5/12/17
to PDFTron WebViewer
Thank you very much. This works as intended.
Reply all
Reply to author
Forward
0 new messages