[Solved] Android Read PDF Document by WebView

Public on September 3, 2015
One of the most requested features in Android is the ability to display a PDF document within a WebView. However, the WebView does not contain a PDF plugin that allow you to display a PDF document. One solution is to use an Intent object to launch a third-party app (such as Adobe Acrobat) which can handle the PDF document. However, this will transfer control over to the thrid-party app.

If you insists on displaying the PDF document within your own activity using a WebView, you can use the following trick. You can use Google Docs to open your PDF document and then load the URL of Google Docs using the WebView.

    protected void onCreate(Bundle savedInstanceState) {
        WebView webView=new WebView(MainActivity.this);

        //---you need this to prevent the webview from
        // launching another browser when a url
        // redirection occurs---
        webView.setWebViewClient(new Callback());
        String pdfURL = "http://dl.dropboxusercontent.com/u/37098169/Course%20Brochures/AND101.pdf";
"http://docs.google.com/gview?embedded=true&url=" + pdfURL);


    private class Callback extends WebViewClient {
        public boolean shouldOverrideUrlLoading(
                WebView view, String url) {

The loaded PDF document will look something like this:

Remember to add in the android.permission.INTERNET permission.

[Advertising]Faster Thinking - Speed up your brain

Faster Thinking Game

sentiment_satisfied Emoticon