Juanjo
Juanjo

Reputation: 969

Open pdf in cordova app (android)

I want to open a pdf in my android app, made with cordova. The problem is every solution I see open the pdf with external apps, and I want to open the pdf in my app, without leaving my app, and when the pdf is closed, the user is still in the app.

Any suggestions?

Thanks in advance

Upvotes: 1

Views: 2094

Answers (3)

user5091906
user5091906

Reputation: 166

url = "https://docs.google.com/gview?embedded=true&url="+YOUR_PDF_LINK;
    var documentLink = cordova.InAppBrowser.open(url, '_blank', 'location=no,hardwareback=yes');

    documentLink.addEventListener('loadstart', function(event) {

    });

    documentLink.addEventListener('exit', function(event) {
        documentLink.removeEventListener("loadstart", function(e){});
    });

You need to install a plugin cordova.InAppBrowser

Upvotes: 1

Víctor
Víctor

Reputation: 3039

Exists some plugins, which can make a PDF reader inside an app. The problem is that all plugins for cordova, for reading PDFs, require a license. Check PDFTron and PSPDFKit

Upvotes: 2

Gandhi
Gandhi

Reputation: 11935

In Android, its generally advisable to send an intent and open pdf using the applications of user's choice. But if your requirement mandates you to open pdf within the app, then there are few solutions to it. You can use mozilla's PDF.js within cordova webview to acheive this. You may also use Google Docs Viewer plugin for jQuery. Check out this link for details. But i dont understand why you are so specific about opening the pdf within app, when you have options to open it in applications of your choice and you can still return back to your app. Cordova File Opener Plugin is what i m using for pdf viewing.

Upvotes: 2

Related Questions