简体   繁体   English

使用手机间隙打开pdf

[英]Open pdf using phone gap

I wan't to open a pdf file on Xcode using phone gap[corodova 1.7.0]. 我不会使用手机间隙[corodova 1.7.0]在Xcode上打开pdf文件。 Is it possible ? 可能吗 ? I can read text files, but for pdf should I use a plugin or something ? 我可以阅读文本文件,但是对于pdf,我应该使用插件还是其他东西? Thanks. 谢谢。

Why don't you try child browser plugin to view pdf in phonegap app. 您为什么不尝试使用子浏览器插件在phonegap应用中查看pdf。

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!");
    }

No need to use plugin rigth now(cordova 2.4+) 现在无需使用插件绑定(cordova 2.4+)

IFRAME is not a solution. IFRAME不是解决方案。

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 . 适用于本地pdf文件的Phonegap PDF Viewer插件但失败

You can open PDF's directly within iframe element. 您可以直接在iframe元素中打开PDF。

Another option which is worth of trying - pdf.js: https://github.com/mozilla/pdf.js 另一个值得尝试的选择-pdf.js: https//github.com/mozilla/pdf.js

for local pdf files use: 对于本地pdf文件,请使用:

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

Solution

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

This code will open the pdf in android phones 此代码将在android手机中打开pdf

Before using this, First add phonegap.js to your HTML page 使用此方法之前,首先将phonegap.js添加到您的HTML页面

You could use pdf embedding using an iframe with the following url 您可以使用带有以下网址的iframe使用pdf嵌入

If your PDF URL is http://yourdomain.com/your_pdf_name.pdf then you should use the following code 如果您的PDF URL是http://yourdomain.com/your_pdf_name.pdf ,则应使用以下代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM