0

I am developing an app for android, ios and windows. One of the requirements is being able to download a pdf that is stored in the assets folder in the ionic app. I am using this plugin https://ionicframework.com/docs/native/file-opener/. I am executing this code as per the documentation.

this.fileOpener.open(‘assets/pdf-test.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));

However I get the following error

“file not found”

Please help

skydev
  • 1,867
  • 9
  • 37
  • 71

1 Answers1

0

assetsfolder only works in your app. What you are telling these others apps to do is to read help_doc.pdf out of their assets, and they do not have such a file.

try this code , but if not work , some time browser not support open pdf , then go must go with plugin fileOpener2

var location = cordova.file.applicationDirectory +"www/assets/MobiMedPrivacyPolicy.pdf";
      window.resolveLocalFileSystemURL(location, function(fileEntry) {

        window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + '/Download/', function(dirEntry) {

          fileEntry.copyTo(dirEntry, "MobiMedPrivacyPolicy.pdf", function(newFileEntry) {

            window.open(newFileEntry.nativeURL, '_blank', 'location=no');
          });
        });
      },function(error)
      {
        console.log(error)
      });
Bahgat Mashaly
  • 510
  • 7
  • 15