5

I have searched already and not found any solution for show pdf file in application

The point is i have to show pdf from asset or raw folder not from web

I have already tried in webview with code

    WebView webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setContentDescription("application/pdf");
    webview.loadUrl("file:///android_asset/button11.pdf");

but its not woking.

i need help on that thanks in advance

djk
  • 3,671
  • 9
  • 31
  • 40

3 Answers3

1

This is the code I use to read a pdf from the filesystem, I hope it helps!

        File file = new File("/path/to/file");          
        Uri path = Uri.fromFile(file);      
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        try {
             context.startActivity(intent);
            } 
         catch (ActivityNotFoundException e) {
             Toast.makeText(context, "No application available to view PDF", Toast.LENGTH_LONG).show();
            }
Twobard
  • 2,553
  • 1
  • 24
  • 27
0

You can't just use file:///android_asset/button11.pdf to access file. It isn't file system path. And webview will not show your pdf even if your get file real path.

Here is the solution. https://stackoverflow.com/a/10981194/1635488

Community
  • 1
  • 1
android_dev
  • 3,886
  • 1
  • 33
  • 52
0

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