10

I'm looking for a pdf viewer for Android using Phonegap 2.0. I tried the childbrowser plugin which worked on iOS but not on Android. I tried this http://www.giovesoft.com/2011/08/download-and-open-pdf-with-phonegap.html but that didn't work either, I get error messages like PhoneGap is not defined at file and cannot call method "showPdf" of undefined.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Leon van der Veen
  • 1,652
  • 11
  • 42
  • 60

5 Answers5

3

you can use pdf.js :

pdf.js is an HTML5 technology experiment that explores building a faithful and efficient Portable Document Format (PDF) renderer without native code assistance.

https://github.com/mozilla/pdf.js

Mohammad Razeghi
  • 1,574
  • 2
  • 14
  • 33
  • Thanks, I already used this plugin but on some PDF files the rendering is not optimal. – Leon van der Veen Sep 12 '12 at 13:20
  • 1
    I also tried out pdf.js, but may impression is that it is too slow for production use on mobiles. It has to repaint for every page and zoom factor. – akohout Sep 13 '13 at 07:54
1

I answered a similar question already (see Open PDF with PhoneGap in Android) but will do the same here. Use the ChildBrowser plugin as suggested in conjunction with Google Docs like so:

onclick='window.plugins.childBrowser.showWebPage(encodeURI("http://docs.google.com/viewer?url=' + pdfLink + '"));

This works fine for me and I have tested it in Android 2.1 up to 4.1.

Community
  • 1
  • 1
Ian Devlin
  • 18,534
  • 6
  • 55
  • 73
0

The childbrowser plugin which I tried with does not open the pdf in android phonegap. However, it works for iOS. Another solution to your plugin query could be to use the Open With plugin. There is one disadvantage that this plugin does not open the pdf in the app itself. You can use the downloader plugin to download files and then try out the childbrowser plugin to access this pdf, which I think should be the solution

user1638126
  • 79
  • 1
  • 4
0

In Android, you can view the pdfs using Android Intents. This will show you all the pdf viewers available in your phone. You can select any and view the pdf

Eg :

private void showPdfAndroid(String url) throws IOException {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(url);

    String extension = url.substring(url.lastIndexOf(".")+1);
    String type = "";

    if (extension.toLowerCase().equals("pdf")) {
        type = "application/pdf";
        Log.d("application/pdf", "application/pdf");
    } 

    intent.setDataAndType(Uri.fromFile(file), type);
    cordova.getActivity().startActivity(intent);

    Log.d("FileViewerPlugin", "View complete in" + url);


}
0

Child browser don't support pdf viewing in android . better you use Google docs viewer for it in android . here in another stack overflow question you will get complete answer

Community
  • 1
  • 1
Ashisha Nautiyal
  • 1,389
  • 2
  • 19
  • 39