5

How to Embed a PDF into HTML and show it in web view ? Actually i am trying this but webview not loaded this page.

    String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
            String pdfPath = base + "/Principal.pdf";
             Log.e("real path =", ""+pdfPath);
            web.getSettings().setJavaScriptEnabled(true);
            web.getSettings().setAllowFileAccess(true);
            web.getSettings().setBuiltInZoomControls(true);
            web.loadDataWithBaseURL("", 
                    "<embed src='"+pdfPath+"' width='500' height='375'>",
                    "application/pdf",
                    "utf-8",
                    "");
Rohit Goswami
  • 617
  • 5
  • 17

1 Answers1

0

May it will be helpful:

For ONLINE:

String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl(url);

For OffLine:

try
{
 Intent intentUrl = new Intent(Intent.ACTION_VIEW);
 intentUrl.setDataAndType(url, "application/pdf");
 intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 myActivity.startActivity(intentUrl);
}
catch (ActivityNotFoundException e)
{
 Toast.makeText(myActivity, "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437