16
Views
6
Comments
Solved
cordova.plugins is always returns undefined
Question

I am trying to use this cordova plugin (https://www.npmjs.com/package/cordova-plugin-document-viewer) to display PDF.

I followed all the steps mentioned here: https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/Mobile_Plugins/Using_Cordova_Plugins

But after integrating the plugin, I get the following error every time I use it.

cordova.plugins. SitewaertsDocumentViewer is undefined.


Rank: #17845
Solution

I was able to integrate https://www.npmjs.com/package/cordova-plugin-pdf-viewer-android and view the PDF within the App and NOT via a 3rd party application.

Rank: #68

Hi Shishir,


Have you tried generating a new version of the app and install the new version on your phone?

When an app uses a new plugin, a new version needs to be generated.


Regards,
João


Rank: #17845

Sorry, no luck.

Screenshot20201208040923.jpg

Rank: #94

Hello Shishir,

Hope you're doing well.

According to your original post, your first error was something like "cordova.plugins.SitewaertsDocumentViewer is undefined".

Like João said, this error happens when a new plugin is not installed in your builds, therefore you'll need to regenerate your builds and install a newer version of your application that contains the new plugin.


Now, according to the image in your last post, it seems to be a different problem: "Cannot read property 'viewDocument' of undefined", which probably means that you are trying to access viewDocument property of a variable that has been declared but it doesn't have an assigned value (undefined). So if you try to access a property of that variable, it will automatically throw an exception (cannot read property of undefined).

Look at this example that may help you to understand. If I try to access length property of an undefined variable, it will raise an exception "Cannot read property 'length' of undefined".


So I'd say that most likely your error is an applicational error, probably related on how you are implementing your client actions and the JavaScript associated to them.


Anyway, as I can see, you are trying to use a plugin in order to display a PDF file. Maybe you would like to consider the usage of File Viewer Plugin for that purpose :)

This plugin is already implement, meaning that the client actions are ready to be used. You could use OpenDocument client action to show your PDF file.


You can follow this thread with an implementation of this plugin where the objective was to show a PDF file: https://www.outsystems.com/forums/discussion/66476/file-plugin-and-file-viewer-plugin-on-android-device/


Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #17845

Hello Rui,

Thanks for your prompt response. 


Cordova Plugin

Also thank you for explaining 'undefined' variables in JS. The problem with the cordova plugin is that I am getting "Cannot read property 'viewDocument' of undefined" when I try to call this line:

cordova.plugins. SitewaertsDocumentViewer. viewDocument. I dug further and I found out that for console.log(cordova.plugins. SitewaertsDocumentViewer) I was getting 'undefined'.

Despite following their usage instructions here (https://github.com/sitewaerts/cordova-plugin-document-viewer#plugin-initialization), I am getting undefined for console.log(cordova.plugins. SitewaertsDocumentViewer). 


FilePicker Plugin

I tried using File Viewer Plugin, but it is trying to open the PDF using external applications like Adobe. I tried changing the isToPreview option still no luck. Device Platform: Android

Is there anyway I can open the PDF within the application?

Rank: #94

Hello Shishir,

Unfortunately, isToPreview option is a feature only available for iOS.

To be honest, I usually use File Viewer Plugin and yes, it opens the PDF using external applications.


If you want to open the PDF within the application, perhaps you can check these samples:

https://www.outsystems.com/forge/component-overview/8504/pdf-viewer-sample-in-mobile

https://www.outsystems.com/forge/component-overview/6223/mobile-pdf-preview


The first one basically uses an Iframe with the file's URL and opens it within the app.

Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #17845
Solution

I was able to integrate https://www.npmjs.com/package/cordova-plugin-pdf-viewer-android and view the PDF within the App and NOT via a 3rd party application.