0

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.

4
  • you can use zohn zapata library Commented Jul 20, 2018 at 12:48
  • use this library 'com.github.barteksc:android-pdf-viewer:2.1.0' Commented Jul 20, 2018 at 12:50
  • Inside App .NO . You need to use some library for it . And AFAIK google doc viewer have some quota policy . So after sometimes it will give you error. Commented Jul 20, 2018 at 12:51
  • you can use this library AndroidPdfViewer github.com/barteksc/AndroidPdfViewer Commented Jul 20, 2018 at 13:16

1 Answer 1

5

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...
        }
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanku "Gokul Nath KP", i know its a good way to open PDF file, but when i m using the above code it closes my app for a moment and then open external pdf application. My requirement is to display the PDF file inside my app, as a part of it(with header and another contents available inside Activity).
Thanku so much, saved my day, Instead of using 3rd party library this is the best way for faster loading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.