Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocumentViewer not working with Ionic 3

I tried to work with ionic/cordova plugin here.

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:

<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:

enter image description here

UPDATE:

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

enter image description here

UPDATE 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:

enter image description here

like image 703
Houssem Badri Avatar asked Oct 16 '17 12:10

Houssem Badri


1 Answers

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

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.

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

Hope that helps someone!

like image 91
Uniphonic Avatar answered Oct 11 '22 03:10

Uniphonic