Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Display PDF File with in the same App in phonegap

how to show Pdf file with in the same phonegap app. i tried Inappbrowser,Mupdf,PDFJS all are displaying PDF using other pdf viewer.i would like to open the pdf file with in the same app.Can anyone help me out.Thanks in advance

like image 803
k.nagababu Avatar asked Apr 23 '15 06:04

k.nagababu


People also ask

Why is it showing Cannot display PDF?

To fix a PDF file not opening in Adobe reader, you will need to download the latest version of Adobe Reader. After which you will disable the protected mode that comes with it by default. Once this is changed, the issue of the PDF file not opening in Adobe reader will be resolved.

What is the best way to display a PDF in a web app?

Using a Simple Link It uses an HTML <a> tag which links to the PDF document. This is, on the one hand, is great, as it delegates the responsibility of dealing with the PDF to the platform itself (e.g. your Mac or PC or phone). Each and every device can display a PDF, in its own way.


3 Answers

for cordova, sachinM's answer is perfect - but with an extensions Use uriEncodeComponent(link) and https://docs.google.com/viewer?url= link

Doc, Excel, Powerpoint and pdf all supported.

Use the cordova in app browser.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
        }

            $("body").on("click",function(e){
           var clicked = $(e.target);
         if(clicked.is('a, a *'))
       {
             clicked = clicked.closest("a");
             var link = clicked.attr("href");
            if(link.indexOf("https://") !== -1)
           {
               if(true) //use to be able to determine browser from app
                 {
                    link = "http://docs.google.com/viewer?url=" +  encodeURIComponent(link) + "&embedded=true";
             }

                 window.open(link, "_blank", "location=no,toolbar=no,hardwareback=yes");
                return false;
            }
    }
    });
like image 73
Marc Magon Avatar answered Oct 19 '22 05:10

Marc Magon


(Excuse my poor English) I don't know what you mean "in the same app", because inappbrowser, Mupdf and pdf.js can all do that.

In Android platform, most popular solution is send intent and open via other pdf viewers because users can choose there favorite(you can try File Opener 2). If you don't like that, you can build an Activity for displaying pdf in your app, just like MuPDF Viewer. If you want open pdf file in Cordova/Phonegap webview, you need mozilla's PDF.js, that's a pure-js lib for rendering pdf file on HTML5 canvas, but it pretty slower than using native solution (even you build with Crosswalk), so I dont suggest that.

It's much easier in iOS platforms. iOS's UIWebView can open pdf files natively, so all you need is using inAppBrowser Plugin. If you want more features, there're many plugins (like Cordova PDFReader IOS) you can choose.

Hope that helps with you.

like image 40
Fomahaut Avatar answered Oct 19 '22 07:10

Fomahaut


You can use Google Docs Viewer plugin for jQuery to display pdf document in div. Click here

like image 1
sachinM Avatar answered Oct 19 '22 06:10

sachinM