我使用Transfer Plugin从服务器下载了一个pdf文件,我试图使用InAppBrower插件打开该文件,但我没有得到任何结果。我的意思是什么也没发生。
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');
});
我的console.log(entry.nativeURL);打印此路径
file:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf
答案 0 :(得分:0)
尝试将nativeUrl放在browserURL中,看看你是否可以跳转到精确的.pdf ....
然后尝试
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');
});

从&ion; native-native'
导入InAppBrowser
import {InAppBrowser} from 'ionic-native';

答案 1 :(得分:0)
我使用此代码,它的作品适用于我
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)
}