Ionic-native: docs(document-viewer): Docs not clear

Created on 15 May 2017  Â·  5Comments  Â·  Source: ionic-team/ionic-native

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior:
There is a problem with the Document Viewer docs.

The example says:

const options = {
  title: 'My PDF'
}
this.document.view('assets/myFile.pdf', 'application/pdf', options)

However:

  1. There is no method called view.
  2. Options needs to be of a type DocumentViewerOptions[]. Is this actually correct? Why is it an array?

Most helpful comment

I use it like this:

constructor(platform: Platform, public navCtrl: NavController, public navParams: NavParams, private document: DocumentViewer) {
    platform.ready().then(() => {
      const options: DocumentViewerOptions = {
        title: 'RCP'
      };
      this.document.viewDocument('http://website.com/file.pdf', 'application/pdf', options);
    });

For the above example(with online hosted pdf) I got this errors:

Error in SitewaertsDocumentViewer.canViewDocument(): Objectdetails: "java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.canGetFile(DocumentViewerPlugin.java:678)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.doExecute(DocumentViewerPlugin.java:351)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.access$000(DocumentViewerPlugin.java:48)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin$1.run(DocumentViewerPlugin.java:184)↵ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)↵ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)↵ at java.lang.Thread.run(Thread.java:818)↵"message: "Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference"status: 9__proto__: Object
plugins/cordova-plugin-document-viewer/www/sitewaertsdocumentviewer.js:344 Error in SitewaertsDocumentViewer.viewDocument():

If I use local path this.document.viewDocument('./assets/file.pdf', 'application/pdf', options); I get:`

Error in SitewaertsDocumentViewer.canViewDocument(): {status: 9, message: "Relative URIs are not supported.", details: "java.lang.IllegalArgumentException: Relative URIs …a:588)↵ at java.lang.Thread.run(Thread.java:818)↵"}
sitewaertsdocumentviewer.js:344 Error in SitewaertsDocumentViewer.viewDocument(): {status: 9, message: "Relative URIs are not supported.", details: "java.lang.IllegalArgumentException: Relative URIs …a:588)↵ at java.lang.Thread.run(Thread.java:818)↵"}

Still don't know how to use and make this work...

All 5 comments

Hey @dylanvdmerwe,
the example is wrong. The right method is called viewDocument().
I fixed it and your second question too (no array).

so, how to declare the options?

If I add DocumentViewerOptions to my imports and add
`IonViewDidEnter(){

const options: DocumentViewerOptions = {
title: 'My PDF'
}
this.document.viewDocument('assets/pdf/firebase.pdf', 'application/pdf', options)

}`

Then I get no errors.
However how do I actually display the pdf?

I use it like this:

constructor(platform: Platform, public navCtrl: NavController, public navParams: NavParams, private document: DocumentViewer) {
    platform.ready().then(() => {
      const options: DocumentViewerOptions = {
        title: 'RCP'
      };
      this.document.viewDocument('http://website.com/file.pdf', 'application/pdf', options);
    });

For the above example(with online hosted pdf) I got this errors:

Error in SitewaertsDocumentViewer.canViewDocument(): Objectdetails: "java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.canGetFile(DocumentViewerPlugin.java:678)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.doExecute(DocumentViewerPlugin.java:351)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.access$000(DocumentViewerPlugin.java:48)↵ at de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin$1.run(DocumentViewerPlugin.java:184)↵ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)↵ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)↵ at java.lang.Thread.run(Thread.java:818)↵"message: "Attempt to invoke virtual method 'boolean java.io.File.exists()' on a null object reference"status: 9__proto__: Object
plugins/cordova-plugin-document-viewer/www/sitewaertsdocumentviewer.js:344 Error in SitewaertsDocumentViewer.viewDocument():

If I use local path this.document.viewDocument('./assets/file.pdf', 'application/pdf', options); I get:`

Error in SitewaertsDocumentViewer.canViewDocument(): {status: 9, message: "Relative URIs are not supported.", details: "java.lang.IllegalArgumentException: Relative URIs …a:588)↵ at java.lang.Thread.run(Thread.java:818)↵"}
sitewaertsdocumentviewer.js:344 Error in SitewaertsDocumentViewer.viewDocument(): {status: 9, message: "Relative URIs are not supported.", details: "java.lang.IllegalArgumentException: Relative URIs …a:588)↵ at java.lang.Thread.run(Thread.java:818)↵"}

Still don't know how to use and make this work...

@tHesTx i have the exact same scenario, how did you manage to solve it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lycwed picture lycwed  Â·  4Comments

jgw96 picture jgw96  Â·  3Comments

GunaSekhar1 picture GunaSekhar1  Â·  4Comments

mateo666 picture mateo666  Â·  3Comments

kyleap picture kyleap  Â·  4Comments