简体   繁体   English

使用WebView在Android中显示PDF

[英]PDF display in Android using WebView

I'm trying to display PDF in Android using WebView , I'm using google docs for this purpose. 我正在尝试使用WebView在Android中显示PDF,为此我正在使用google docs It was working fine till this morning. 直到今天早上,一切都很好。 But all of a sudden it's throwing 502 error. 但是突然之间,它抛出502错误。 Is there any alternative to display PDF's in WebView . 是否有其他选择可以在WebView显示PDF。

This is the URL I have been using to render PDF in WebView 这是我用来在WebView呈现PDF的URL

https://docs.google.com/gview?embedded=true&url= +URL https://docs.google.com/gview?embedded=true&url= + URL

It looks like https://docs.google.com/gview?embedded=true&url= is down. 看来https://docs.google.com/gview?embedded=true&url=关闭状态。

Try this way 试试这个

@Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        if (url.endsWith(".pdf"))
        {
            // Load "url" in google docs

           String googleDocs = "https://docs.google.com/viewer?url="; 
           mWebView.loadUrl(googleDocs + url);

        }
        else
        {
            // Load all other urls normally.
            view.loadUrl(url);
        }

        return true;
     }

UPDATE try this 更新尝试这个

webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);

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

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