Sana Joseph
Sana Joseph

Reputation: 1948

Open pdf using phone gap

I wan't to open a pdf file on Xcode using phone gap[corodova 1.7.0]. Is it possible ? I can read text files, but for pdf should I use a plugin or something ? Thanks.

Upvotes: 1

Views: 13281

Answers (6)

jafarbtech
jafarbtech

Reputation: 7015

You could use pdf embedding using an iframe with the following url

If your PDF URL is http://yourdomain.com/your_pdf_name.pdf then you should use the following code

<iframe src="https://docs.google.com/viewer?url=http://yourdomain.com/your_pdf_name.pdf&embedded=true"></iframe>

Upvotes: 0

Mohit
Mohit

Reputation: 51

Solution

window.open("http://docs.google.com/viewer?url=" + pdflink +" ");

This code will open the pdf in android phones

Before using this, First add phonegap.js to your HTML page

Upvotes: 1

Tom Cool
Tom Cool

Reputation: 11

for local pdf files use:

window.open('./any.pdf', '_blank', 'location=no');

Upvotes: 0

Uğur &#214;zpınar
Uğur &#214;zpınar

Reputation: 1043

No need to use plugin rigth now(cordova 2.4+)

IFRAME is not a solution.

OBJECT, EMBED is not a solution.


Solution

window.open('http://example.com/any.pdf', '_blank', 'location=no');

This code will open a child browser.


Phonegap PDF Viewer plugin made for local pdf files and It fails.

Upvotes: 2

Mayur Birari
Mayur Birari

Reputation: 5835

Why don't you try child browser plugin to view pdf in phonegap app.

function onDeviceReady() {

        var root = this;
        cb = window.plugins.childBrowser;

        if(cb != null) {
        cb.onLocationChange = function(loc){ root.locChanged(loc); };
        cb.onClose = function(){root.onCloseBrowser(); };
        cb.onOpenExternal = function(){root.onOpenExternal(); };
        cb.showWebPage("http://xyz.com/server/data/test.pdf");

        }
    }

    function onCloseBrowser() {
        console.log("onCloseBrowser!");
    }

    function locChanged(loc) {
        console.log("locChanged!");
    }

    function onOpenExternal() {
        alert("onOpenExternal!");
    }

Upvotes: 4

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19049

You can open PDF's directly within iframe element.

Another option which is worth of trying - pdf.js: https://github.com/mozilla/pdf.js

Upvotes: 1

Related Questions