DocumentViewer无法使用Ionic 3

时间:2022-06-01 21:24:11

I tried to work with ionic/cordova plugin here.

我试着在这里使用ionic / cordova插件。

So I put this code in my Page:

所以我把这段代码放在我的页面中:

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

And a simple button to launch it in the html page:

还有一个简单的按钮可以在html页面中启动它:

<ion-content>
  <button  ion-button round (click)="showDocument()">
    Read
  </button>
</ion-content>

But I can't see anything in the emulator (since it is not possible to run it on the browser)

但我在模拟器中看不到任何内容(因为无法在浏览器上运行它)

Ionic Info is there:

离子信息在那里:

DocumentViewer无法使用Ionic 3

UPDATE:

更新:

This is what I get when debugging with my device and chrome devtools:

这是我使用我的设备和chrome devtools进行调试时得到的结果:

DocumentViewer无法使用Ionic 3

UPDATE 2:

更新2:

I have tried to work with absolute paths but I have got null value, I have made those changes:

我试图使用绝对路径,但我有空值,我做了这些更改:

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)

But see what I have got:

但看看我得到了什么:

DocumentViewer无法使用Ionic 3

1 个解决方案

#1


1  

This does not answer your question directly, but is a workaround for getting PDFs to display.

这不是直接回答您的问题,而是一种解决方法,可以显示PDF。

I had trouble with a lot of plugins for reading PDFs, so I ended up just using a Mozilla project called PDF.js to render the PDF directly in the browser on the Android platform, and on iOS they are displayed natively in the browser. To handle it like a viewer, separately from the rest of my app, I used an in app browser window.

我在浏览PDF时遇到了很多插件,所以我最终只使用一个名为PDF.js的Mozilla项目直接在Android平台的浏览器中呈现PDF,而在iOS上它们本身就在浏览器中显示。为了像查看器一样处理它,与我的应用程序的其余部分分开,我使用了一个应用程序浏览器窗口。

There are some code examples for PDF.js here: http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples

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

Hope that helps someone!

希望有人帮助!

#1


1  

This does not answer your question directly, but is a workaround for getting PDFs to display.

这不是直接回答您的问题,而是一种解决方法,可以显示PDF。

I had trouble with a lot of plugins for reading PDFs, so I ended up just using a Mozilla project called PDF.js to render the PDF directly in the browser on the Android platform, and on iOS they are displayed natively in the browser. To handle it like a viewer, separately from the rest of my app, I used an in app browser window.

我在浏览PDF时遇到了很多插件,所以我最终只使用一个名为PDF.js的Mozilla项目直接在Android平台的浏览器中呈现PDF,而在iOS上它们本身就在浏览器中显示。为了像查看器一样处理它,与我的应用程序的其余部分分开,我使用了一个应用程序浏览器窗口。

There are some code examples for PDF.js here: http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples

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

Hope that helps someone!

希望有人帮助!