how to open an Offline pdf in ionic 2 application in adobe reader

1.4k views Asked by At

Trying the below code to open an offline pdf in ionic 2 application but the code is opening a pdf file in cleverdox viewer instead of adobe reader, how could i set adobe reader by default here to make pdf functional. Thanks in Advance.

open()
  {
  const options: DocumentViewerOptions = {
  title: 'My PDF'
  }
  this.document.viewDocument('file:///android_asset/www/assets/test.pdf', 'application/pdf', options)
}

2

There are 2 answers

1
rajesh On

Try openWith() like below,

open()
  {
  const options: DocumentViewerOptions = {
  title: 'My PDF',
  openWith() {
    enabled: true
   }
  }
  this.document.viewDocument('file:///android_asset/www/assets/test.pdf', 'application/pdf', options)
}
0
Matthew M On

No idea if you got this resolved but here's what fixed the issue for me:

Make sure you are using the latest version of the document Viewer plugin.

open() {
  const options: DocumentViewerOptions = {
    title: 'My PDF',
    openWith: { enabled: true }, //this will allow you to open the document with an external application
    // any more options
  };
  this.document.viewDocument('file:///android_asset/www/assets/test.pdf', 'application/pdf', options);
}

The problem with @rj7 's code is that he added a function into what should be a nested object. For more information on the options you can pull through into this function, see the following URL: https://github.com/sitewaerts/cordova-plugin-document-viewer

Hope that helps to anyone stuck in the future.