Learner
Learner

Reputation: 810

Viewing a PDF file from HTML5 Hybrid Mobile App

Intending to view a PDF File from the Hybrid Mobile App , created using HTML5 Jquery and Packaged with Phonegap.

But unable to achieve it ,

Things i tried

<object src="xyz.pdf" type="application/pdf"></object>

also,

 window.open('xyz.pdf'); //through javascript

and

$(document).load('xyz.pdf');

Can anyone suggest the best way for viewing the PDF in a Hybrid Android Mobile App.

Upvotes: 1

Views: 9315

Answers (5)

Lohith Korupolu
Lohith Korupolu

Reputation: 1074

Though am late here, still want to share what I know. You can use this plugin to view PDFs in the app (without inappbrowser). Supports only Android and iOS.

Upvotes: 0

demaniak
demaniak

Reputation: 3915

Go look at the Mozilla pdfJS project.

This project allows you to open a pdf (embedded in app or remote) in your app. No break-out links that relies on native viewers.

They also give you a very full featured sample viewer, that you can use as is, but much of functionality in that does not apply to mobile applications.

I have had success with this on Android 4.3 Devices.

Upvotes: 1

AJD
AJD

Reputation: 46

My solution for connected apps with offline availability...

window.open('http://www.someserver.com/doc.pdf', '_system')

...this will open in default pdf viewer. I have my clients use adobe reader for obvious reasons. And also because once it is downloaded the first time, adobe app manages and edits the documents well, and the documents are also available offline from within adobe reader thereafter. Even pdf forms.

Have cordova.js linked on the page. Have inAppBrowser added.

For full offline you may try FileOpener plugin. I have not needed to do that on android, but I have used that way in iOS.

Hope any of this may help.

Upvotes: 0

VicM
VicM

Reputation: 2479

Try installing the InAppBrowser plugin to do so. I have use it to open PDF files right inside the app on both iOS and Android.

Check the official InAppBrowser doc with full doc and examples, it has several options you can enable/disable (be sure to point to your current cordova version documentation):

Upvotes: 0

phemt.latd
phemt.latd

Reputation: 1803

with cordova you must think about these:

HTML 5 object tag: not working

If you try with:

 window.open('http://www.???.com/my.pdf', '_blank', 'location=yes');

The InAppViewer can´t open this kind of files.

I think that there aren't an hybrid solution for this problem. You must start to search or write about a plugin that use a native pdf's opening and then use it. An example:

cordova-plugin-file-opener

The latest solution, a little more simple but include to open google docs is:

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');

Upvotes: 2

Related Questions