Bhavin Padiya
Bhavin Padiya

Reputation: 87

document-viewer in ionic not working not open file

Hello I use followring code not working How to Resole It..

 fileTransfer.download(url, path + 'abcd.pdf').then((entry) => {
            let localUrl = entry.toURL();
            const toast = this.toast.create({
              message: 'Download Complted',
              duration: 20000,
              position: 'top',
              closeButtonText: 'OK',
              showCloseButton: true,
            });
            toast.present();
            this.document.viewDocument(localUrl, 'application/pdf', {});
        }, (error) => {
            // handle error
            console.log("In error");
            console.log(error);
            alert(JSON.stringify(error));
        });

How to be it working!!

Upvotes: 0

Views: 1764

Answers (1)

Jaydeep Kataria
Jaydeep Kataria

Reputation: 867

Did you add document viewer plugin in you project? please see this link https://ionicframework.com/docs/native/document-viewer/ you can find commands.

ionic cordova plugin add cordova-plugin-document-viewer
npm install --save @ionic-native/document-viewer

Then you have to pass options also in viewDocument functions

      fileTransfer.download(url, path + 'abcd.pdf').then((entry) => {
            let localUrl = entry.toURL();
            const toast = this.toast.create({
              message: 'Download Complted',
              duration: 20000,
              position: 'top',
              closeButtonText: 'OK',
              showCloseButton: true,
            });
            toast.present();
             const options: DocumentViewerOptions = {
             title: 'My PDF'
            }
            this.document.viewDocument(localUrl, 'application/pdf', options);
        }, (error) => {
            // handle error
            console.log("In error");
            console.log(error);
            alert(JSON.stringify(error));
        });

Hope this will work for you!

Upvotes: 1

Related Questions