How to open an local pdf using InAppBrowser

半腔热情 提交于 2019-12-24 05:02:29

问题


I have downloaded an pdf file from the server using Transfer Plugin and i am trying to open the file using InAppBrower plugin i am not getting anything. i mean nothing is happening.

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 path file:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf


回答1:


Try putting the nativeUrl in the browserURL and see if you could jump 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');
    });

And import InAppBrowser from 'ionic-native'

import {InAppBrowser} from 'ionic-native';



回答2:


i use this code and its 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)
    }


来源:https://stackoverflow.com/questions/44427319/how-to-open-an-local-pdf-using-inappbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!