Matt Butler
Matt Butler

Reputation: 57

Opening PDF in Phonegap (Android)

I have tried for some time to figure this out but I cannot get a solution. I have a local PDF that I need to open either in the app itself or in a 3rd party app (whatever works). I need to have it so that no other applications need to be downloaded for it to work. Does anyone know a good solution for this? I have tried inAppBrowser and some other javascript solutions.

Upvotes: 0

Views: 955

Answers (1)

Hi You can open the file with the FileOpener plugin, open a PDF document with the default PDF reader app.

File opener plugin

Install:

cordova plugin add https://github.com/pwlin/cordova-plugin-file-opener2

Usage:

cordova.plugins.fileOpener2.open(
    '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
    'application/pdf', 
    { 
        error : function(e) { 
            console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
        },
        success : function () {
            console.log('file opened successfully');                
        }
    }
);

Upvotes: 2

Related Questions