gaddam nagaraju
gaddam nagaraju

Reputation: 187

Child browser is not showing content of pdf in browser in android phonegap

I have been working on pdf reader in android phonegap since two days..I am new to the phonegap..child browser plugin is working but the pdf file link is appearing in the browser with a blank page.I have added plugins and phonegap with a version of coredova 2.0.0 and added plugins..where i was wrong?can any one solves my problem..Thanks in advance.

     <!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Child Browser Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
    <script type="text/javascript" charset="utf-8" src="childbrowser.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for PhoneGap to load
    //
    function Bodyload(){
        document.addEventListener("deviceready", onDeviceReady, false);
    }
    // PhoneGap is ready
    //
    function onDeviceReady() {
         console.log("PhoneGap is ready");
         window.plugins.childBrowser.showWebPage( "http://www.google.com/****/" );
    }
    </script>
  </head>
  <body onload="Bodyload();" id="stage" class="theme">    
  </body>
</html>

Upvotes: 0

Views: 2324

Answers (3)

santinobonora
santinobonora

Reputation: 38

i think the problem is because of android automatically places "http://" in front of your url if it isn't there already. but i also dont know how to solve this issue. (im trying to fix the issue. so if i know more i will post it here)

var yourURL = "data:application/pdf;base64," + btoa(pdfOutput)  
//btoa() makes its value to base64

window.open(yourURL, "_blank", 
  "location=yes"            //set to no if you do not want to have any url bar
+ "enableViewportScale=yes" //set to "no" if your target should not zoom the pdf
);

output url bar:

http://data:application/pdf;base64,(somecode)

what we want to reach:
data:application/pdf;base64,(somecode)

Upvotes: 0

Vikas Panwar
Vikas Panwar

Reputation: 399

I have solved this problem by using following code.. first check the url string last three characters if these are pdf use if condition otherwise use else condition.where WebUrl is the url you want to open. this solution works for all Android versions(Tested on API 9 to 4.1).

if(checkPDF === 'pdf') { window.plugins.childBrowser.showWebPage('http://docs.google.com/viewer?url='+WebUrl+''); } else { window.plugins.childBrowser.showWebPage(WebUrl); }

Upvotes: 0

Prangya
Prangya

Reputation: 26

The pdf will not get render as android webview does not support rendering pdf and the childbrowser uses android webview. Instead you can use some third party sdks for rendering in Android. Most of them require license(like quoppa,pdfViewer). I have not seen any opensource but you can look into the follwing link

https://github.com/jblough/Android-Pdf-Viewer-Library

For ios you can use pspdfkit.They are providing a cordova plugin also. go through the following link. https://github.com/PSPDFKit/PSPDFKit-Cordova

Upvotes: 0

Related Questions