如何使用 InAppBrowser 打开本地 pdf

人气:836 发布:2022-10-16 标签: filepath cordova inappbrowser ionic2 ionic3

问题描述

我已经使用 Transfer Plugin 从服务器下载了一个 pdf 文件,我正在尝试使用 InAppBrower 插件打开文件我没有得到任何东西.我的意思是什么都没有发生.

fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{标题:{'授权':'承载者xxxx'}}).then((入口) => {console.log('下载完成:' + entry.toURL());console.log(entry.nativeURL);常量浏览器 = this.iab.create(entry.nativeURL, '_system', 'location=yes');//这里是inappbrowser插件代码.},(错误)=>{//处理错误控制台日志(错误);console.log('错误');});

我的控制台.log(entry.nativeURL);打印此路径 file:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf

解决方案

我使用此代码及其对我的工作

showDocument(){常量选项: DocumentViewerOptions = {标题:我的 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', 选项)}

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

解决方案

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)
    }

541