2

I ahve a webview in my layout screen. I need to display a PDF file in that webview from my assets folder. I tried below code. While running app displays zoom in and out controls with a blank page(our PDF file is kind of large.is it due to that?).

 webView = (WebView) findViewById(R.id.webView1);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);


    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) //required for running javascript on android 4.1 or later
    {
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    }
    settings.setBuiltInZoomControls(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("file:///android_asset/test.pdf");

I dont want to use external apps to read my PDF. is it possible?then how?

andro-girl
  • 7,989
  • 22
  • 71
  • 94

3 Answers3

1

This question is answered already . For the details refer the following links.
How to read pdf in my android application?.
One more is
stackoverflow.com/questions/10299839/how-to-read-pdf-in-my-android-application/10352422#10352422

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
Simon Chius
  • 476
  • 5
  • 18
1

You can use pdf.js from Mozilla to display a PDF in a webview inside an Android application.

Here is the solution...

https://stackoverflow.com/a/21383356/2260073

Community
  • 1
  • 1
sravanalakshmi.sunkara
  • 1,161
  • 2
  • 13
  • 35
-1

After searching a lot about this i came up with my own kind of solution

I used this website to convert my PDF to DOCX and then DOCX to HTML using online converters and then used the following code to load the HTML in my Webview.

String htmlString = "<p>YOUR HTML CODE</p>";


webView.loadData(htmlString, "text/html", "UTF-8");

Hope this helps!

Siddy Hacks
  • 1,846
  • 14
  • 15