Ariel N. Mogro Ariel N. Mogro - 3 months ago 52
Android Question

Pdf view android studio

Hello community wanted to know how to view a PDF file in android api eight studio try these codes but can not = (someone tell me what's wrong? ..
I get all the WebView blank
  thanks

WebView wv = (WebView)findViewById(R.id.webView2);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});
wv.loadUrl("www.ues.mx/Docs/alumnos/movilidad/Ejemplo%20de%20Curr%C3%ADculum%20Vitae.pdf");

wv.getSettings().setUseWideViewPort(true);


another way

WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("www.ues.mx/Docs/alumnos/movilidad/Ejemplo%20de%20Curr%C3%ADculum%20Vitae.pdf");
setContentView(webview);


PluginsEnabled replaced

webView.getSettings().setPluginState(WebSettings.PluginState.ON);


not work in any way help!

Answer

WebView cannot display PDF documents in Android.

You can handle the pdf to either download it and then open a 3rd party app as shown here.

Or you can also use Google Drive viewer.

String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl(url);
Comments