我尝试使用Ionic/Cordova插件进行工作。
因此,我将以下代码放入我的页面中:
showDocument() {
var options: DocumentViewerOptions = {
title: 'A book',
documentView: { closeLabel: '' },
navigationView: { closeLabel: '' },
email: { enabled: true },
print: { enabled: true },
openWith: { enabled: true },
bookmarks: { enabled: true },
search: { enabled: false },
autoClose: { onPause: false }
}
this.docViewer.viewDocument('assets/arabic.pdf', 'application/pdf', options);
}
同时在HTML页面中添加一个简单的按钮以启动它:
<ion-content>
<button ion-button round (click)="showDocument()">
Read
</button>
</ion-content>
但我在模拟器中看不到任何东西(因为它不能在浏览器中运行)
Ionic信息在这里:
更新:
使用我的设备和Chrome开发工具进行调试时,我得到了以下结果:
更新2:
我尝试使用绝对路径工作,但是我得到了空值,我已经做出了以下更改:
import { File } from '@ionic-native/file';
declare let cordova: any;
//staff
pdfSrc: string = cordova.file.applicationDirectory + 'assets/arabic.pdf';
//staff
console.log(this.pdfSrc);
this.document.viewDocument(this.pdfSrc, 'application/pdf', options)
但是看看我得到了什么: