Best method to render a pdf on a view in android

309 views Asked by At

I know there are many library's available which are not suitable for commercial use like mupdf.My company is a startup and is not in a position to spend a lot .I am working on a magazine app.Can anyone suggest a good open-source library to use for rendering a single pdf or if that is not possible which one among the paid one's shall i prefer ? Thanks in advance

1

There are 1 answers

1
Raghunandan On

You can use webview with google docs.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<WebView
android:id="@+id/wv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/> 

 WebView wv= (WebView) findViewById(R.id.wv);
 wv.setVerticalScrollBarEnabled(true);
 wv.setHorizontalScrollBarEnabled(true);
 wv.getSettings().setBuiltInZoomControls(true);
 wv.getSettings().setJavaScriptEnabled(true);
 wv.setWebViewClient(new WebViewClient());
 wv.loadUrl("https://docs.google.com/file/d/0B8ZDVNCvRWK8c3YzQVFaWjg1bEU/edit")//pdf uploaded to google docs. Some cases requires users to login and requires permission of the owner of the doc.

You can use intent. Your phone must have a pdf reader application.

  File file = new File("/sdcard/example.pdf");
            if (file.exists()) {
                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 {
                    startActivity(intent);
                } 
                catch (ActivityNotFoundException e) {
                    Toast.makeText(OpenPdf.this, 
                        "No Application Available to View PDF", 
                        Toast.LENGTH_SHORT).show();
                }

http://code.google.com/p/apv/source/checkout. APV PDF Viewer

http://code.google.com/p/apdfviewer/. APDF Viewer.