[File Viewer Plugin] [Mobile offline] Open PDF from entity's binary data

Forge Component
(6)
Published on 28 Aug by Experts
6 votes
Published on 28 Aug by Experts

How to open pdf (which is binary data in an entity) in offline mode ? Target is for both iOS and Android devices. I am able to display nicely when mobile is online. For offline mode, I tried below 




Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

Pedro Sousa wrote:

Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

Thanks Pedro.

Tried creating the plugin using CommonPlugin, but it fails as FileOpener undefined.Replacing FileOpener with FileOpener2 has same result.

if(typeof(cordova.plugins.FileOpener) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;




Mukul Varshney wrote:

Pedro Sousa wrote:

Unfortunately, this Forge component doesn't support opening/previewing files straight from their base64-encoded contents.

You can try to wrap the cordova-plugin-file-opener2 cordova plugin, which supports your use case through the openBase64() method, in an OutSystems plugin.

Check "Create a Plugin to Use Mobile Capabilities in Your Application" for more information on how to do this.

Thanks Pedro.

Tried creating the plugin using CommonPlugin, but it fails as FileOpener undefined.Replacing FileOpener with FileOpener2 has same result.

if(typeof(cordova.plugins.FileOpener) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;




Able to locate the problem and proceed,

if(typeof(cordova.plugins.fileOpener2) === "undefined")
    $parameters.PluginExists = false;
else
    $parameters.PluginExists = true;


Still it does not open the PDF file.

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Valerie wrote:

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Path property of the client action GetFileURI will be 

"data:application/pdf;base64," + JavaScript1.Base64

Is it correct ?

Solution

Hi using the File Plugin we used Create Directory to create a folder for the app in the phone then we used the SaveFile to save the binary file in the folder created. This path cannot be accessed unless the phone is jail break or rooted. so Example the path is "com/test/MobileApp"

Then for the GetFileURI that is the path that we put. 


Note that for the SaveFile no need to convert to base64 you can directly point the binary data from Local Storage.

Mukul Varshney wrote:

Valerie wrote:

Hi,

Try using the File Plugin from Forge  to save the binary file locally. 

Use the File Plugin to save it locally. 

use the GetFileURI to get the path then place it in filePath in OpenDocument to open the binary file.




Path property of the client action GetFileURI will be 

"data:application/pdf;base64," + JavaScript1.Base64

Is it correct ?



Solution

Mukul Varshney & Valerie : With above solution , i was able to achieve the functionality of downloading PDF from mobile app through binary data. Thank you for the same.

However, i wanted to know that after using this plugin, when we deploy the version to production, End user would be required to reinstall the app or just update it from play store ? It would not be good to get the app reinstalled by thousands of users just for one change in app.

Please let me know if anyone has faced such issue. Thanks.

Vani Mankad wrote:

Mukul Varshney & Valerie : With above solution , i was able to achieve the functionality of downloading PDF from mobile app through binary data. Thank you for the same.

However, i wanted to know that after using this plugin, when we deploy the version to production, End user would be required to reinstall the app or just update it from play store ? It would not be good to get the app reinstalled by thousands of users just for one change in app.

Please let me know if anyone has faced such issue. Thanks.


After adding any new plugin we need to generate and have a new build for the app. This new build has to be published to the app store. Probably, a new installation required on phones.

Is that the case for Production deployment as well ? I understand for Development environment, it will require to get reinstalled the app because the build will be deployed on "Debug" mode.

But for Production deployment also we need user to get it reinstalled the app ?

I cannot confirm, most likely the app has to be reinstalled by the user as the cordova plugin is changed and the hence the app has be installed again.