djk
djk

Reputation: 3691

Open asset file pdf in application

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

Upvotes: 5

Views: 10899

Answers (3)

sravanalakshmi.sunkara
sravanalakshmi.sunkara

Reputation: 1161

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

Upvotes: 0

android_dev
android_dev

Reputation: 4188

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

Upvotes: 0

Twobard
Twobard

Reputation: 2583

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();
            }

Upvotes: 1

Related Questions