DocumentViewer在Ionic 3中无法工作

8

我尝试使用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)

但是看看我得到了什么:

输入图像描述


1
{btsdaf} - Suraj Rao
{btsdaf} - Houssam Badri
1
{btsdaf} - user6490462
1
{btsdaf} - user6490462
@ErnestoUlloa 谢谢你,但是这个方法也没有起作用,我已经尝试过了。而且你有没有注意到,它还是以ionic 1的风格编码的? - Houssam Badri
显示剩余8条评论
1个回答

1

这并没有直接回答你的问题,但是有一个解决方法可以让PDF文件显示。

我尝试了很多阅读PDF文件的插件,最终我使用了一个名为PDF.js 的Mozilla项目,在Android平台上直接在浏览器中呈现PDF文件,在iOS上则在浏览器中本地显示。为了将其作为查看器与我的应用程序分开处理,我使用了一个应用内浏览器窗口

这里有一些关于PDF.js的代码示例: http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples

希望能对某些人有所帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接