sarika
sarika

Reputation: 47

how to display Pdf file from url inside android app

I am creating an Android app. How do I display a PDF file inside an Android from a url? without using already available system's pdf viewer application. Currently i am using webview and the code is:

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

but it is taking too much time to load and display PDF file. Is there any another fast way to do this.

Upvotes: 0

Views: 4236

Answers (1)

Gokul Nath KP
Gokul Nath KP

Reputation: 15574

Do not use google docs, as it has limit. Best way is to use external PDF application installed on device. Loading and rendering a PDF depends on your network speed, processing capacity and file size.

You can use below code to load PDF in default viewer.

    public openPDFViewer(String url) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            startActivity(intent);
        } catch (Exception e) {
            // Error...
        }
    }

Upvotes: 5

Related Questions