Phonegap Inappbrowser Display PDF 2.7.0

Phonegap InAppBrowser display pdf 2.7.0

For everybody who is stuck with this problem here is what i´ve finally found out:

HTML 5 object tag: not working

Embedded tag: not working

childBrowser Plugin:
I think it would work, but it is designed for the 2.0.0 version. So you´ll get a lot of errors so i didn´t get it to work.

Phonegap InAppViewer:
If you use it like that:

window.open('http://www.example.com/test.pdf', '_blank', 'location=yes')

it wont work. The InAppViewer can´t open PDF, it doesn´t matter if the PDF is external or local stored.

My solutions so far (not what the actual idea was):

you can call the window function with _system. like that:

window.open('http://www.example.com/test.pdf', '_system', 'location=yes')

this will open the PDF in the normal Browser and download it. After downloading it will ask if it should open it with a PDF viewer. But you have to go back to your app and open it again after that.

Another possibility would be that you just download it to your sdcard with the Phonegap Filesystem API like that:

var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"file://sdcard/ics-android.png",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});

The last thing i´ve found out is, to use Google docs/drive to open it with the InAppViewer linked to google docs like that:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

window.open('https://docs.google.com/viewer?url=http://www.example.com/test.pdf&embedded=true', '_blank', 'location=yes');
ref = window.open('index.html', '_self');
}

This will open the PDF in the app viewing it on google docs.
You can generate your permalink here:
https://docs.google.com/viewer
So even if you change your pdf file, it will still work

I hope this summary will help you save time. If there is another solution let me know

InAppBrowser not loading pdf Phone gap 2.7.0

Try This..

    var ref = window.open("https://docs.google.com/gview?embedded=true&url=http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf", '_blank', 'location=yes');

Becuse Andoid Webkit has not power to Directly open pdf as IOS.. So open with google Doc.

Not able to launch a pdf file in inappbrowser in android

Unlike iOS, which has a built-in PDF viewer - Android's webview does not have PDF viewer built-in.

This is why it is going to fail in Android.

You have 2 choices in Android:

  1. View the file using Google Docs by storing the file at a remote server and redirecting the user like so: window.open(encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf'), '_blank', 'location=yes,EnableViewPortScale=yes');

  2. Or use a Cordova plug-in. For example this one (you can search in Google for more). For this, you'll need to learn how to create Cordova plug-ins in Worklight.

You can read more options here: Phonegap InAppBrowser display pdf 2.7.0

Phonegap build - Open external page in InAppBrowser or childbrowser with no toolbar and close it?

OK, problem 1 to close is solved.
This is what I use to open an external page in the InAppBrowser.
From the page that I load in the InAppBrowser, I can close the InAppBrowser itself, returning to my app from where I opened the browser.

Create a page on your server - closeInAppBrowser.html that is just an empty html page, it doesn´t do anything

I open the browser with this:

<a href="#" onclick="openInAppBrowserBlank('http://www.mypage.asp?userId=1');">open InAppBrowser</a>

var ref = null;
function openInAppBrowserBlank(url)
{
try {
ref = window.open(encodeURI(url),'_blank','location=no'); //encode is needed if you want to send a variable with your link if not you can use ref = window.open(url,'_blank','location=no');
ref.addEventListener('loadstop', LoadStop);
ref.addEventListener('exit', Close);
}
catch (err)
{
alert(err);
}
}
function LoadStop(event) {
if(event.url == "http://www.mypage.com/closeInAppBrowser.html"){
// alert("fun load stop runs");
ref.close();
}
}
function Close(event) {
ref.removeEventListener('loadstop', LoadStop);
ref.removeEventListener('exit', Close);
}

And to close the InAppBrowser from the page that I opened in the browser(http://www.mypage.asp) I have a button-link like this.

<a href="http://www.mypage.com/closeInAppBrowser.html"></a>

I hope it helps somebody else!



Related Topics



Leave a reply



Submit