我有一个pdf网址。当我尝试在浏览器中打开它时。但是,当我尝试在Android和ios设备中打开时。我的pdf文件无法查看。这是我的代码:
我的控制器:
$window.OpenLink = function(link) {
window.open( link, '_system');
};
我的html代码点击:
<div class="col col-50 clsGrid" onclick="OpenLink('http://www.orimi.com/pdf-test.pdf')">
请帮帮我。如何打开我的pdf文件并在android和ios设备中查看。
提前致谢 !!
安装插件
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
然后尝试这个
<a class="item" href="#" onclick="window.open('http://www.orimi.com/pdf-test.pdf', '_system', 'location=yes'); return false;">
Open pdf
</a>
类似的问题在这里问。 Ionic framework PdfViewer
尝试使用这个Phonegap插件https://github.com/ti8m/DocumentHandler它非常适合我。
以下是我整合它的方式。
$scope.HandleDocumentPlugin = function () {
if (DocumentViewer != null) {
DocumentViewer.previewFileFromUrlOrPath(
function () {
console.log('success');
}, function (error) {
if (error == 53) {
console.log('No app that handles this file type.');
var alert = $ionicPopup.alert({
title: 'Alert!',
template: "There is no app installed that handles this file type."
});
alert.then(function (res) {
});
}
}, $scope.PDF_URL);
}
else if (DocumentHandler != null) {
DocumentHandler.previewFileFromUrlOrPath(
function () {
console.log('success');
}, function (error) {
if (error == 53) {
console.log('No app that handles this file type.');
var alert = $ionicPopup.alert({
title: 'Alert!',
template: "There is no app installed that handles this file type."
});
alert.then(function (res) {
});
}
}, $scope.PDF_URL);
}
else {
console.log("error");
}
}