2012-05-09 6 views
3
I want to display pdf file in webview. 
I try using this code it displays blank page. 
File retrieve perfacly but not display in webView. 
Put screen shoot of webview displays webview when i run the application. 
display blank webview. like this....

enter image description hereアンドロイド負荷のWebViewで(資産/ RES /外部記憶装置に)pdfファイル

private WebView view; 
Uri path; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     view = (WebView) findViewById(R.id.webView); 
     File file = new File(Environment.getExternalStorageDirectory() 
       .getAbsolutePath() + "/Documents/MyPDFFILE.pdf"); 
     path = Uri.fromFile(file); 
     view.setContentDescription("application/pdf"); 
     view.getSettings().setJavaScriptEnabled(true); 
     view.getSettings().setLoadsImagesAutomatically(true); 
     view.getSettings().setPluginsEnabled(true); 
     view.getSettings().setAppCacheEnabled(true); 
     view.loadUrl(path.toString()); 

     // view.loadUrl("http://grail.cba.csuohio.edu/~matos/notes/cis-493/lecture-notes/Android-Chapter10-WebKit.pdf"); 
    } 
+0

コメントコードi load internet pdfもwebviewに読み込まれません。しかし、私はGoogleのPDFビューアのリンクを使用する "https://docs.google.com/viewer?url=http://grail.cba.csuohio.edu/~matos/notes/cis-493/lecture-notes/Android- Chapter 10-WebKit.pdf "を開き、デフォルトのブラウザで開きますが、webviewでは開きません。 –

答えて

2

地元のAndroid WebViewPDFファイル機能をサポートしていません、ので。 WebViewはPDFをレンダリングできません。

あなたのコメントに投稿したURLは、がGoogleドキュメントを使用しているため、ネイティブウェブブラウザでPDFファイルを表示しました。

あなたのwebviewにpdfファイルを表示するには、あなたのローカルにないサーバーにあるあなたのpdfファイルのGoogle Docs pass URLを使用します。

更新: webviewのネット上に表示されるpdfファイルのコード。

WebView webview = (WebView) findViewById(R.id.webview); 
webview.getSettings().setJavaScriptEnabled(true); 
String pdf = "http://www.xxxx.com/xxxx/xxxx.pdf"; 
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf); 
+9

しかし、問題は、ローカルのPDFファイルのためにこれを行う方法でしたが、この解決策もその場合も機能しますか? –

関連する問題