How to open local pdf using InAppBrowser

I have downloaded a PDF file from the server using the "Transfer Plugin" and I am trying to open the file using the InAppBrower plugin. I am not getting anything. I mean, nothing happens.

fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
        headers: {
            'authorization': 'bearer xxxx'
        }
    }).then((entry) => {
      console.log('download complete: ' + entry.toURL());
      console.log(entry.nativeURL);
      const browser = this.iab.create(entry.nativeURL, '_system', 'location=yes'); //here the inappbrowser plugin code.
    }, (error) => {
      // handle error
      console.log(error);
      console.log('ERROR');
    });

      

my console.log (entry.nativeURL); prints this pathfile:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf

+2


source to share


2 answers


Try putting nativeUrl in browserURL and see if you can navigate to the exact .pdf ....

Then try

fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
        headers: {
            'authorization': 'bearer xxxx'
        }
    }).then((entry) => {
      console.log('download complete: ' + entry.toURL());
      console.log(entry.nativeURL);
      let browser=new InApp Browser(entry.nativeURL,'_blank');
    }, (error) => {
      // handle error
      console.log(error);
      console.log('ERROR');
    });
      

Run codeHide result




And import InAppBrowser from "ionic-native"

import {InAppBrowser} from 'ionic-native';
      

Run codeHide result


0


source


I am using this code and it works for me



showDocument(){
      const options: DocumentViewerOptions = {
        title: 'My PDF'
      }
      const imgeLocation = `${cordova.file.applicationDirectory}www/assets/imgs/${'Jainbhajan-Jeevan-Saar-By-Nirmal-Gangwal-1-ilovepdf-compressed (1).pdf'}`;
      this.document.viewDocument(imgeLocation, 'application/pdf', options)
    }

      

0


source







All Articles